Description
From https://internals.rust-lang.org/t/extremely-pre-rfc-eprintln/4635 …
if you are writing command-line programs: the easiest way to emit non-fatal error messages is
println!
, but that sends them tostdout
, which is not where error messages should go.panic!
does the right thing (and thus alsounwrap
,expect
,assert!
, etc) but those are all (a) fatal and (b) properly used only for conditions that indicate a bug. The most straightforward way to write diagnostics tostderr
iswriteln!(io::stderr(), "out of cheese error").unwrap();
which is significantly more typing in itself, requires you to
use std::io::Write
, and doesn't haveprintln!
's defensive measures against being called at an awkward moment.The simplest thing we could possibly add to fix this problem would be an
eprintln!
macro, which would be exactly the same asprintln!
except that the output goes to stderr instead of stdout.All of the documentation should also be updated to make it clear that it is inappropriate to use
println!
for error messages.
… which met with general approval and two people saying they already were adding eprintln!
to all their own crates, so I'm just gonna go ahead and submit a PR. eprint!
is included for completeness and symmetry; I'm not sure it's useful, but I think people would be surprised to find it missing.