Skip to content

Misleading error messages #71

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

Closed
TheButlah opened this issue Sep 30, 2024 · 1 comment
Closed

Misleading error messages #71

TheButlah opened this issue Sep 30, 2024 · 1 comment

Comments

@TheButlah
Copy link

The error messages cmd_lib gives don't seem as intuitive as bash. Consider the following code:

fn main() -> color_eyre::Result<()> {
    color_eyre::install()?;

    let log_to_find = "evilevil";
    cmd_lib::run_cmd! {
        info "this is a log message";
        pwd;
        cat log.txt | grep $log_to_find;
    }?;

    Ok(())
}

This produces this error:

❯ cargo run
   Compiling foo v0.0.0 (/Users/ryan.butler/P/scratch/foo)
    Finished dev [unoptimized + debuginfo] target(s) in 0.21s
     Running `target/debug/foo`
[INFO ] this is a log message
/Users/ryan.butler/P/scratch
[INFO ] cat: log.txt: No such file or directory
Error:
   0: Running ["grep" "evilevil"] exited with error; status code: 1 at foo/src/main.rs:5

Location:
   foo/src/main.rs:5

But in bash, I get:

❯ cat log.txt | grep evilevil
cat: log.txt: No such file or directory
@tao-guo
Copy link
Collaborator

tao-guo commented Oct 1, 2024

The truth is that: the error was indeed from grep, even in bash (w/ or w/o pipefail):

$ ls /xx | grep y
ls: cannot access '/xx': No such file or directory
$ echo $?
1
$ ls /xx
ls: cannot access '/xx': No such file or directory
$ echo $?
2
$ echo /xx | grep y
$ echo $?
1
$ set -o pipefail
$ ls /xx | grep y
ls: cannot access '/xx': No such file or directory
$ echo $?
1

We have also logged the stderr output, so you can find out why it caused the grep to fail. Note ideally the log level should be WARN/ERROR, however the library only knows there was information from stderr and they are OK in most of the cases.

@tao-guo tao-guo closed this as completed in b6aeab4 Oct 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants