mesabox icon indicating copy to clipboard operation
mesabox copied to clipboard

Better format for error messages

Open mssun opened this issue 7 years ago • 4 comments

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

mssun avatar Jul 12 '18 05:07 mssun

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.

Arcterus avatar Jul 12 '18 17:07 Arcterus

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

mssun avatar Jul 12 '18 18:07 mssun

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.

Arcterus avatar Jul 12 '18 18:07 Arcterus

Ok, agree.

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

mssun avatar Jul 12 '18 18:07 mssun