-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ErrorKind::ProcessFailed and impl From<ExitStatusError> #88306
Conversation
We add this to the existing feature gate exit_status_error, since we will probably want to stabilise this trait impl along with the new type - or not at all. Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
This should be fine on all actual Unix platforms since errno values are quite conventional, especially very basic ones like ENOENT. Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
This comment has been minimized.
This comment has been minimized.
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you as always for the attention you're giving to improving the Command
APIs. I see the value to providing more convenient ways to invoke Command
s, and I think your goal with this PR is quite similar to @matklad's goal with #89004, which I agree with. However, I really worry that making it possible to automatically shove an ExitStatusError
into an io::Error
will encourage bad error reporting habits.
I think @matklad probably has the right balance of convenience and reporting. If we're going to collapse the error types we should do so in a way that works as a reasonable default and include the extra context such as the command which was run.
library/std/src/io/error.rs
Outdated
/// A custom error that does not fall under any other I/O error kind. | ||
/// | ||
/// This can be used to construct your own [`Error`]s that do not match any | ||
/// [`ErrorKind`]. | ||
/// | ||
/// This [`ErrorKind`] is not used by the standard library. | ||
/// This operation is unsupported on this platform. | ||
/// | ||
/// Errors from the standard library that do not fall under any of the I/O | ||
/// error kinds cannot be `match`ed on, and will only match a wildcard (`_`) pattern. | ||
/// New [`ErrorKind`]s might be added in the future for some of those. | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
Other, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why'd you reorder these? I think this messes with the derived Ord
impl which I'd prefer to avoid without strong justification.
Should this PR be closed then? |
I think this impl makes process error handling a lot more ergonomic. Look at the new example to see what I mean.
If we are going to do this, it makes more sense to do it now, while
ExitStatusError
is unstable. We can experiment with how we like the results, without insta-stably providing the trait impl.There is a possible concern related to the resulting error messages. Because of the way
io::Error
'sDisplay
impl simply forwards to the underlying error, the message"subprocess failed"
won't be part of those errors.But the
Display
impl onExitStatusError
prefixes the message fromExitStatus
with"process exited unsuccessfully"
, which is nicely unambiguous.#84908 (comment) has more discussion about this in the context of the other possible messages arising from process handling, in particular
Command::status()
.Other possibilities
This ability to represent a subprocess failure status as an
io::Error
will be useful in other situations:This would make it possible to provide an
exit_ok
method onCommand
, improving the ergonomics of simple subprocess executions.It would also make it much more possible to provide a version of
Command::output
that is less prone to the programmer accidentally losing the exit status. It would even be possible to provide a "streaming" version of the output: a type which would encompass theChild
and the pipe, andimpl io::Read
, and which would give a read error if the child failed.Just the
ErrorKind
could be helpful for some other libraries that can otherwise useio::Error
for their error handling.Note this MR branch is on top of #88298 which has already been approved and I expect to land soon.
Let me see if I can get highfive to do what I want:
r? @yaahc