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

fail!() writes to stderr #374

Open
mahkoh opened this issue Jul 30, 2014 · 6 comments
Open

fail!() writes to stderr #374

mahkoh opened this issue Jul 30, 2014 · 6 comments

Comments

@mahkoh
Copy link
Contributor

mahkoh commented Jul 30, 2014

fail! writes an error message to stderr. Every function call that can fail is a potential rust error message to stderr. Consider the following code

~/rust/coreutils/build$ ./cat /etc/fstab | grep -L 
Usage: grep [OPTION]... PATTERN [FILE]...
Try 'grep --help' for more information.
task '<main>' failed at 'called `Result::unwrap()` on an `Err` value: broken pipe (Broken pipe)', /build/rust-git/src/rust/src/libcore/result.rs:548

This is not how cat should behave. There are currently 129 calls to unwrap() in coreutils.

There is currently no way to make fail! simply call abort which would probably be sufficient for coreutils. You can use stdio::set_stderr to set the writer used by fail!() or you can remove every call that can fail.

Note that println! will also call fail on sigpipe. There are currently 420 occurrences of println!.

@Arcterus
Copy link
Collaborator

Not every call to unwrap() is at risk of failing. However, I agree that those that are should be fixed.

I added pipe_println! a little while ago to handle the SIGPIPE. It should probably not fail in the case of another error, though.

@mahkoh
Copy link
Contributor Author

mahkoh commented Jul 30, 2014

Using set_stderr is the simpler solution. You only have to do this in mkmain.rs and src/uutils/uutils.rs. You can also use libc::?::signal to turn on sigpipe's default behavior.

@Arcterus
Copy link
Collaborator

Arcterus commented Aug 5, 2014

I don't think we want to ignore an occurrence of fail! that shouldn't occur (such as when there is a bug in the program). However, we do want to _prevent_ fail! from being called in the case of a normal error (e.g. incorrect arguments, issue opening a file, etc.).

I hadn't thought about using signal. That's probably the best solution for the SIGPIPE.

@Arcterus
Copy link
Collaborator

I think this can be fixed by just adding panic = "abort" to all the Cargo.tomls now.

@stale
Copy link

stale bot commented Mar 27, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Mar 27, 2021
@rivy rivy removed the wontfix label Jan 21, 2022
@stale
Copy link

stale bot commented Jan 21, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants