main discussion reminded me of another way in which Rust currently makes the easy thing be the wrong thing, if you are writing command-line programs: the easiest way to emit non-fatal error messages is
println!, but that sends them to
stdout, which is not where error messages should go.
panic! does the right thing (and thus also
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 to
writeln!(io::stderr(), "out of cheese error").unwrap();
which is significantly more typing in itself, requires you to
use std::io::Write, and doesn’t have
println!'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 as
println! except that the output goes to stderr instead of stdout. (It’d be more natural to call it
error! instead, but the
log crate already snagged that one.) (I’m not sure whether we want
eprint! as well — progress messages also belong on stderr, and often don’t want a newline, but it might turn out to be just as easy to keep using
write! for those.)
All of the documentation should also be updated to make it clear that it is inappropriate to use
println! for error messages.