-
Notifications
You must be signed in to change notification settings - Fork 34
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
Include the command that failed in the error #109
Comments
Good point, we should fix this. While we're at it, how do you feel about output like |
I always use color-eyre in my binary crates, and that one actually prints it much more nicely.
Having said that, it would be really nice to be able to copy the error message command and paste it into a terminal directly. For that purpose I ended up adding a wrapper so I could log every command being run: /// Wrapper around `duct::cmd` function that lets us log the command we're running.
pub fn cmd_log<T, U>(l: log::Level, program: T, args: U) -> duct::Expression
where
T: duct::IntoExecutablePath + Clone,
U: IntoIterator + Clone,
U::Item: Into<OsString>,
{
let mut formatted_cmd = format!(
"Running cmd: {program}",
program = shell_escape::escape(program.clone().to_executable().to_string_lossy())
);
for arg in args.clone() {
write!(
formatted_cmd,
" {arg}",
arg = shell_escape::escape(arg.into().to_string_lossy())
)
.unwrap();
}
log::log!(l, "{formatted_cmd}");
duct::cmd(program, args)
} This prints something like:
Which avoids using quotes unless you actually need them (and which I find nicer to read). The need to
I find that spaces are quite common in commands I end up running (especially on macOS, where lots of system paths have spaces in them). |
Using
duct
has been a great improvement for shell-heavy Rust, but one issue I end up running into a fair bit is that when a user of my CLI hits an error that isn't the command returning a non-zero exit status, the error doesn't tell you what command was run.As an example, if you run this (as a
main.rs
in acargo new
after acargo add duct
):Then you get the following output:
When the command returns a non-zero exit code you get an error that tells you what command was run, but in other failure modes you don't.
It would be really useful to always have the command in the error message, no matter what the error was.
The text was updated successfully, but these errors were encountered: