eprintln
This is a bit of a follow-up to https://github.com/redox-os/coreutils/issues/186, I got an idea while reviewing code for error handling in userutils and redox_users: This is a pattern that we see an AWFUL lot of:
let user = get_user_by_id(euid).unwrap_or_else(|err| {
eprintln!("whoami: {}", err);
exit(1);
});
A situation where an error occurs and the program prints it's name, followed by a colon, followed by the error to stderr and then exits (with a nonzero exit code).
Most (if not all) of these programs have an instance of parser in scope for the entirety of the main function, and this pattern is most often seen as a part of the main function. ArgParser
already has access to the correct prefix for the format error, so I wonder if we could do one of the following:
- Create a method on
ArgParser
(or a function that takesArgParser
, or something similar) that effectively does this given afailure::Error
- Create a macro that somehow accomplishes this, given an instance of
ArgParser
and an error.
I have no experience or knowledge of writing macros, but it's a thought.