Skip to content

Add std::process::Output::exit_ok #554

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

Closed
lolbinarycat opened this issue Mar 3, 2025 · 1 comment
Closed

Add std::process::Output::exit_ok #554

lolbinarycat opened this issue Mar 3, 2025 · 1 comment
Labels
ACP-accepted API Change Proposal is accepted (seconded with no objections) api-change-proposal A proposal to add or alter unstable APIs in the standard libraries T-libs-api

Comments

@lolbinarycat
Copy link

Proposal

Problem statement

checking process exit statuses is not erganomic enough, even with the exit_status_error feature.

Motivating examples or use cases

ExitStatus::exit_ok cannot be called in a one-liner, so it is common to see slightly incorrect usages such as
Command::new("rustc").args(&["--print", "sysroot"]).output().stdout, which will silently ignore any exit code.

Solution sketch

impl Output {
  fn exit_ok(self) -> Result<Self, ExitStatusError> {
    self.status.exit_ok()?;
    self
  }
}

This would be part of the existing exit_status_error feature gate. This would not replace ExitStatus::exit_ok, as that type would still be useful for those who still want to process the commands output even if it is not successful.

Alternatives

  • Separate error type that captures and displays stderr, not just the error code.

Links and related work

What happens now?

This issue contains an API change proposal (or ACP) and is part of the libs-api team feature lifecycle. Once this issue is filed, the libs-api team will review open proposals as capability becomes available. Current response times do not have a clear estimate, but may be up to several months.

Possible responses

The libs team may respond in various different ways. First, the team will consider the problem (this doesn't require any concrete solution or alternatives to have been proposed):

  • We think this problem seems worth solving, and the standard library might be the right place to solve it.
  • We think that this probably doesn't belong in the standard library.

Second, if there's a concrete solution:

  • We think this specific solution looks roughly right, approved, you or someone else should implement this. (Further review will still happen on the subsequent implementation PR.)
  • We're not sure this is the right solution, and the alternatives or other materials don't give us enough information to be sure about that. Here are some questions we have that aren't answered, or rough ideas about alternatives we'd want to see discussed.
@lolbinarycat lolbinarycat added api-change-proposal A proposal to add or alter unstable APIs in the standard libraries T-libs-api labels Mar 3, 2025
@joshtriplett
Copy link
Member

We discussed this in today's @rust-lang/libs-api meeting. The motivation of "give people an ergonomic way to do the right thing so that they don't use an ergonomic way to do the wrong thing" is compelling, and we're approving this ACP.

In the comments of the method, please make it clear that it doesn't do anything to display stderr, so if you aren't inheriting stderr (and thus potentially letting the user see the stderr), you may want to do something more sophisticated than .exit_ok()?.stdout.

lolbinarycat added a commit to lolbinarycat/rust that referenced this issue Apr 8, 2025
lolbinarycat added a commit to lolbinarycat/rust that referenced this issue Apr 8, 2025
lolbinarycat added a commit to lolbinarycat/rust that referenced this issue Apr 15, 2025
Zalathar added a commit to Zalathar/rust that referenced this issue Apr 15, 2025
…=tgross35

std: add Output::exit_ok

approved in ACP rust-lang/libs-team#554

Tracking issue: rust-lang#84908
jieyouxu added a commit to jieyouxu/rust that referenced this issue Apr 15, 2025
…=tgross35

std: add Output::exit_ok

approved in ACP rust-lang/libs-team#554

Tracking issue: rust-lang#84908
Zalathar added a commit to Zalathar/rust that referenced this issue Apr 15, 2025
…=tgross35

std: add Output::exit_ok

approved in ACP rust-lang/libs-team#554

Tracking issue: rust-lang#84908
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Apr 15, 2025
Rollup merge of rust-lang#139554 - lolbinarycat:std-output-exit_ok, r=tgross35

std: add Output::exit_ok

approved in ACP rust-lang/libs-team#554

Tracking issue: rust-lang#84908
@Amanieu Amanieu added the ACP-accepted API Change Proposal is accepted (seconded with no objections) label Apr 15, 2025
@Amanieu Amanieu closed this as completed Apr 15, 2025
github-actions bot pushed a commit to rust-lang/rustc-dev-guide that referenced this issue Apr 17, 2025
github-actions bot pushed a commit to rust-lang/miri that referenced this issue Apr 17, 2025
github-actions bot pushed a commit to model-checking/verify-rust-std that referenced this issue Apr 19, 2025
github-actions bot pushed a commit to model-checking/verify-rust-std that referenced this issue Apr 19, 2025
…=tgross35

std: add Output::exit_ok

approved in ACP rust-lang/libs-team#554

Tracking issue: rust-lang#84908
lnicola pushed a commit to lnicola/rust-analyzer that referenced this issue Apr 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ACP-accepted API Change Proposal is accepted (seconded with no objections) api-change-proposal A proposal to add or alter unstable APIs in the standard libraries T-libs-api
Projects
None yet
Development

No branches or pull requests

3 participants