Skip to content

Stderr #5641

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
SephVelut opened this issue Jun 19, 2018 · 5 comments
Closed

Stderr #5641

SephVelut opened this issue Jun 19, 2018 · 5 comments
Labels
C-question Category: question

Comments

@SephVelut
Copy link

SephVelut commented Jun 19, 2018

I don't get the justification #1473 for switching stdout with stderr. If you want special formatting from stdout then its on you to sed or awk.

From an abstract perspective they are both just file descriptors, but there is no reason to trickle down a formatting use case to how stderr and stdout are conventionally treated by everyone else. That is, write to stderr if the command exited with a code other than 0.

@matklad
Copy link
Member

matklad commented Jun 26, 2018

@SephVelut I don't quite understand what problem exactly are you trying to solve? Could you rephrase your question?

The current strategy for output in Cargo is that all human-reaadble things go to stderr, and all machine readable things go to stdout. That way, you can safely parse Cargo's stdout without accounting for various diagnostic messages.

@matklad matklad added the C-question Category: question label Jun 26, 2018
@SephVelut
Copy link
Author

SephVelut commented Jun 26, 2018

Shouldn't all output go to stdout and reserve stderr for errors in executing the command? Most command line programs expect this. Stderr and stdout can both be piped down at the same time to other commands and stderr can be treated like a failure case. Not of the program but of the command. There's a distinction. Cargo failing to build, for example, is not an error. Undefined arguments to the command are.

I don't think there is a distinction between machine readable and human readable. Unless it's literally binary, that's subjective :)

And shouldn't parsing Cargo's output be the responsibility of the user, using other commands? Like awk or sed.

@alexcrichton
Copy link
Member

This is currently an intentional design decision where you can execute commands like cargo run | foo where foo only receives the output of the program run, nothing from Cargo and/or rustc.

@SephVelut
Copy link
Author

SephVelut commented Jun 28, 2018

Why not just wait for the OP to respond/close? What's the hurry?

I don't understand the reason for the design decision, can you please explain a little more? Wouldn't it be weird if a function that returned Result used Err to report logical or computational results, instead of just a diagnostic of an error if it occurred?

@alexcrichton
Copy link
Member

The design decision here is for all information output of Cargo to go to one stream, stderr. Sort of how all compiler error messages go to stderr as well. The thinking is then that stdout is reserved for programs Cargo runs, so Cargo never produces meaningful output on stdout. That way you can throw away stderr from Cargo or only capture stdout and you're guaranteed to get your program's output

missingdays added a commit to JetBrains/teamcity-rust-plugin that referenced this issue Oct 23, 2020
…utput to stderr, which leads to it being colored in red in build log. See rust-lang/cargo#5641 for more info
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-question Category: question
Projects
None yet
Development

No branches or pull requests

3 participants