mesalock-linux / mesabox

A collection of core system utilities written in Rust for Unix-like systems (and now Windows)
BSD 3-Clause "New" or "Revised" License
137 stars 19 forks source link

Better format for error messages #22

Open mssun opened 6 years ago

mssun commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

Ok, agree.

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