Skip to content
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

Better format for error messages #22

Open
mssun opened this issue Jul 12, 2018 · 4 comments
Open

Better format for error messages #22

mssun opened this issue Jul 12, 2018 · 4 comments

Comments

@mssun
Copy link
Contributor

mssun commented Jul 12, 2018

The current error messages are not consistent and nested together. We should have a better error message format.

mesabox head:

$ ./target/debug/mesabox head -c - tests/fixtures/head/lorem_ipsum.txt
head: error: Invalid value for '--bytes <NUMBER>': '-' is not a number or is too large

mesabox cat:

$ ./target/debug/mesabox cat fdsfs
cat: fdsfs: No such file or directory (os error 2)
cat: encountered 1 error(s)

Some examples for reference:

GNU coreutils:

$ head -c - tests/fixtures/head/lorem_ipsum.txt
head: invalid number of bytes: ‘’

BSD (OS X):

$ head -c - tests/fixtures/head/lorem_ipsum.txt
head: illegal byte count -- -

BusyBox:

$ ./busybox head -c - busybox_unstripped.out
head: invalid number ''

Cargo:

$ cargo build --release sss
error: Found argument 'sss' which wasn't expected, or isn't valid in this context

USAGE:
    cargo build --release

For more information try --help
@Arcterus
Copy link
Contributor

The original plan was for the format to be utilname: error: msg in most cases, but I've started to think the error: bit wastes too much space (as with most of these utilities almost any message written to stderr is an error).

I'm not entirely sure what you mean by "nested together" unless you are referring to Invalid value for '--bytes <NUMBER>': '-' is not a number or is too large, which I believe is a result of clap. I also think the GNU and BusyBox errors messages are not clear unless you already understand how the utility works.

@mssun
Copy link
Contributor Author

mssun commented Jul 12, 2018

For the first question:

  1. utilname: error: msg
  2. error: msg
  3. utilname: msg

I'm not sure which one is better. Seems that Rust's tradition tends to use the second one and "error" is highlighted in red.

For the second question, I mean the error message is in one line and separated in colon. E.g., the current one is:

utilname: error: msg: sub-msg

It looks a little wired (probably because of the prefix utilname: error). Yes, the current message of GNU and BusyBox is not clear, and I was not suggesting to be consistent with them.

cargo uses the same format:

$ cargo build -j abc
error: Invalid value: could not parse `abc` as a number

@Arcterus
Copy link
Contributor

I think we need to keep everything as one line, so the best way to fix this I guess would be to remove the error: part.

@mssun
Copy link
Contributor Author

mssun commented Jul 12, 2018

Ok, agree.

BTW, I'm coming up this issue when writing testcases for errors.

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