Skip to content
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

Closed
wants to merge 7 commits into from

Conversation

ijackson
Copy link
Contributor

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's Display impl simply forwards to the underlying error, the message "subprocess failed" won't be part of those errors.

But the Display impl on ExitStatusError prefixes the message from ExitStatus 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 on Command, 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 the Child and the pipe, and impl 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 use io::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

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>
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 24, 2021
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
@inquisitivecrystal inquisitivecrystal added the T-libs Relevant to the library team, which will review and decide on the PR/issue. label Aug 24, 2021
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>
@rust-log-analyzer

This comment has been minimized.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
@JohnCSimon JohnCSimon added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 13, 2021
@JohnCSimon JohnCSimon added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 3, 2021
Copy link
Member

@yaahc yaahc left a 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 Commands, 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.

Comment on lines 264 to 275
/// 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,
Copy link
Member

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.

@ijackson
Copy link
Contributor Author

ijackson commented Oct 6, 2021

@yaahc Thanks for pointing me at #89004. That does look like it's going in a good directiion. I will make some time to review it properly.

@yaahc yaahc added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 8, 2021
@JohnCSimon JohnCSimon added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 24, 2021
@JohnCSimon JohnCSimon added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 13, 2021
@camelid
Copy link
Member

camelid commented Dec 10, 2021

@yaahc Thanks for pointing me at #89004. That does look like it's going in a good directiion. I will make some time to review it properly.

Should this PR be closed then?

@JohnCSimon
Copy link
Member

Ping from triage:
@ijackson
I'm closing this due to inactivity, Please reopen when you are ready to continue with this. Thank you.

@rustbot label: +S-inactive

@JohnCSimon JohnCSimon closed this Jan 30, 2022
@rustbot rustbot added the S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs. label Jan 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants