Pointing at the error: compiler-style diagnostics in uutils coreutils
Sylvestre Ledru
For 50 years, Coreutils have never stopped evolving. Now, we're pushing that innovation further by rethinking how they report errors.
Unix tools report errors as a single line on stderr. That line says what went wrong, not where. For most commands there is nowhere else to point anyway, but a few take arguments that are small languages: a test expression, a chmod mode, a sort key, a tr set. When one of those fails to parse, what you actually want to know is which argument, or which character of it, the parser tripped over.
rustc has been answering that question with a caret for years, and ariadne puts the same rendering one dependency away. The idea of bringing it to a command-line tool comes from uutils awk, which already reports errors in an awk program that way; coreutils arguments are smaller languages, but they parse just the same. Starting with 0.11.0, coreutils uses it. When stderr is a terminal, a parse error is printed as a report: the arguments are echoed back as a source line, a caret marks the culprit, and a help line explains the syntax when we have something useful to say about it.
What it looks like
Start with tr , whose GNU message assumes you already know what a collating sequence is.
Before:
tr $ tr 'qw[y-b]' x tr: range-endpoints of 'y-b' are in reverse collating sequence order
After:
... continue reading