uniq: match GNU's errors for -f/-s/-w and --group/--all-repeated - #14304
Open
arbelonson-source wants to merge 1 commit into
Open
uniq: match GNU's errors for -f/-s/-w and --group/--all-repeated#14304arbelonson-source wants to merge 1 commit into
arbelonson-source wants to merge 1 commit into
Conversation
Three separate gaps, all in how uniq reports a bad option value:
`-f`/`-s`/`-w` named the option and quoted the value, GNU does neither --
it names what the number counts instead:
$ uniq -f abc f # ours, before
uniq: Invalid argument for skip-fields: abc
$ uniq -f abc f # GNU
uniq: abc: invalid number of fields to skip
`-s` and `-w` say "bytes to skip"/"bytes to compare" instead; each of the
three call sites now says what GNU says for that one.
A value starting with `-` was rejected by clap as an unrecognized flag
instead of being read as the option's own value -- `uniq -f -1` -- needing
`allow_hyphen_values`, the same gap fixed for `sort --parallel` earlier.
`--group` and `--all-repeated` used a clap `ShortcutValueParser`, so a bad
choice got clap's wording, and worse, both used the SAME possible-values
list in the one place `get_delimiter` read them, even though the two
options take different choices with a different canonical order:
$ uniq --group=bogus f # ours, before
error: invalid value 'bogus' for '--group[=<group-method>]'
[possible values: separate, prepend, append, both]
$ uniq --group=bogus f # GNU
uniq: invalid argument 'bogus' for '--group'
Valid arguments are:
- 'prepend'
- 'append'
- 'separate'
- 'both'
Fixed by validating each option's value against its own choice list,
keeping the unambiguous-abbreviation matching `ShortcutValueParser` gave
(`--group=s` still means `separate`).
This also retires a hack in `map_clap_errors`: two branches existed only
to special-case the literal string "badoption" -- the exact value GNU's
own test suite happens to use -- with the *value* hardcoded into the
message text rather than read from the error. That could never have
been correct for a value the user actually typed; both `ShortcutValueParser`
choices being replaced removes the clap error they were built to catch,
and the two tests that exercised them are updated to the real, general
message instead.
This was referenced Aug 31, 2026
Contributor
|
see #14308 (comment) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Three separate gaps, all in how
uniqreports a bad option value.-f/-s/-w: wrong words, wrong quotingGNU names what the number counts, not the option, and never quotes the value.
-ssays "bytes to skip",-wsays "bytes to compare" — each of the three call sites now uses the phrase GNU uses for that one.A value starting with
-was also rejected outright — clap read it as an unrecognized flag rather than this option's value:allow_hyphen_valuesfixes that — the same gap fixed forsort --parallelin #14303 just now.--group/--all-repeated: one clap possible-values list shared by two different optionsBeyond the wording,
get_delimiterread both options' values through the same match arm, so a bad--all-repeatedvalue would have reported--group's list (or vice versa) if either had reached the point clap's own validation was bypassable — the two options don't even take the same choices (--all-repeatedhasnonewhere--grouphasboth, not the reverse). Fixed by validating each against its own list, in its own GNU-documented order, keeping the unambiguous-abbreviation matchingShortcutValueParseralready gave (--group=sstill resolves toseparate).A hack this retires
map_clap_errorshad two branches that existed only to special-case the literal string"badoption"— the exact value GNU's own test suite happens to use — with that value hardcoded directly into the message text rather than read from the error. That could never have been correct for any value a user actually typed instead of "badoption". Removing the twoShortcutValueParsers removes the clap error kind those branches existed to intercept, so they're now dead code; deleted along with the two now-unusedFluentkeys they referenced. The two tests that exercised them (from GNU's own test-case numbering, "119" and "145") are updated to the real, general message rather than the one hardcoded example.Testing
-f/-s/-wwith non-numeric, negative, empty and valid values (both space- and=-separated), and--group/--all-repeatedwith bad, valid, and abbreviated choices: all match (2 apparent mismatches were the test's own binary-path artifact in the--helphint, not a real difference).ShortcutValueParser's behavior wasn't broken — kept as a non-regression check.cargo test --features uniq --test tests -- test_uniq: 40 passed, 0 failed (34 pre-existing — 2 of which needed their hardcoded-"badoption" expectations corrected to the real message — plus 6 new).moz-fluent-lintonsrc/uu/uniq/locales: no errors.cargo fmt --checkandcargo clippy -p uu_uniq --all-targets -- -D warnings: clean.Disclosure
Prepared with AI assistance (Claude Opus 5, via Claude Code), per the AI policy in CONTRIBUTING.md. GNU's behaviour was established by running the installed GNU binary as a black box; I did not read GNU coreutils source. All testing was run locally.