sort: match GNU's error for a bad --parallel value - #14303
Closed
arbelonson-source wants to merge 1 commit into
Closed
sort: match GNU's error for a bad --parallel value#14303arbelonson-source wants to merge 1 commit into
arbelonson-source wants to merge 1 commit into
Conversation
`--parallel` used clap's built-in ranged `u64` parser, so a bad value got
clap's wording instead of GNU's own -- the same class of gap fixed for
other options earlier in this project:
$ sort --parallel=0 f # ours, before
error: invalid value '0' for '--parallel <NUM_THREADS>': 0 is not in 1..18446744073709551615
$ sort --parallel=0 f # GNU 9.11
sort: number in parallel must be nonzero
$ sort --parallel=-1 f # ours, before
error: invalid value '-1' for '--parallel <NUM_THREADS>': invalid digit found in string
$ sort --parallel=-1 f # GNU
sort: invalid --parallel argument '-1'
`--parallel` shares the same number-with-suffix parser `-S`/`--buffer-size`
already uses via `format_error_message`, so this reuses that rather than
inventing new wording: GNU syntactically accepts a suffix here too, but
none is ever valid for a thread count, so the allow list passed to the
parser is empty rather than the one `-S` uses.
A value starting with `-` is still accepted as this option's value, not a
new flag -- `--parallel -1` -- matching GNU. This needed
`allow_hyphen_values`, which the old `value_parser!(u64).range(1..)` did
not have, so `--parallel -1` (space-separated) was already broken before
this change; verified that specific breakage pre-dates this PR.
## Deliberately not covered
GNU accepts an arbitrarily large `--parallel` value without erroring, and
apparently does not actually try to spawn that many OS threads for it.
uutils' `rayon::ThreadPoolBuilder` builds its pool eagerly, so asking for
anywhere near that many threads hangs rather than completing -- a
pre-existing limitation, already reachable today with an ordinary
in-range count (`--parallel 10000` already hangs on current `main`).
Rather than clamp an overflowing value the way `head`/`tail`/`numfmt` do
elsewhere in this project (which would make the hang reachable from an
even wider set of inputs, including ordinary overflow past `u64::MAX`),
this keeps the pre-existing behavior of erroring on overflow, just with a
clearer message. Fixing the hang itself means teaching the thread pool
that `--parallel` is a soft upper bound, not a literal thread count to
build eagerly, which felt like a distinct problem from an error-message
mismatch.
Separately, and also not touched here: sort's `-S`/`--buffer-size` has a
comment acknowledging that GNU echoes back whichever spelling, `-S` or
`--buffer-size`, was actually typed, and that this is not yet implemented
(the message always says "--buffer-size"). `--parallel` has no short
form, so this PR does not need that distinction, but `-S` still does.
This was referenced Aug 31, 2026
Contributor
|
see #14308 (comment) |
This was referenced Aug 31, 2026
|
GNU testsuite comparison: |
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.
Fixes #13016 (message wording; the underlying accept-anything bug that issue reported was already fixed in #13024, but the replacement clap-based validation still doesn't say what GNU says).
--parallelused clap's built-in rangedu64parser, so a bad value got clap's wording instead of GNU's own:--parallelshares the same number-with-suffix parser-S/--buffer-sizealready uses viaformat_error_message, so this reuses that rather than inventing new wording. GNU syntactically accepts a suffix here too (--parallel=2K→invalid suffix in --parallel argument '2K', not a plain "invalid argument"), but no suffix is ever semantically valid for a thread count, so the allow list passed to the parser is empty rather than the list-Suses.A value starting with
-is still accepted as this option's value, not a new flag —sort --parallel -1— matching GNU. That neededallow_hyphen_values, which the oldvalue_parser!(u64).range(1..)never had, so--parallel -1(space-separated, as opposed to--parallel=-1) was already broken before this change; I confirmed that specific breakage onmainand it isn't something I introduced.Deliberately not covered
--parallelvalue without erroring, and apparently does not try to spawn that many OS threads for it. uutils'rayon::ThreadPoolBuilderbuilds its pool eagerly, so asking for anywhere near that many threads hangs rather than completing — a pre-existing limitation already reachable today with an ordinary in-range count (sort --parallel 10000 falready hangs on currentmain, confirmed before this PR). Clamping an overflowing value the wayhead/tail/numfmtdo elsewhere in this project would make that hang reachable from an even wider set of inputs (including ordinary overflow pastu64::MAX), so this keeps the existing behavior of erroring on overflow instead, just with a clearer message. Fixing the hang itself means teaching the thread pool that--parallelis a soft upper bound rather than a literal count to build eagerly for, which felt like a distinct problem from an error-message mismatch.-S/--buffer-sizehas an existing comment insort.rsacknowledging that GNU echoes back whichever spelling was actually typed (-Svs--buffer-size), and that this isn't implemented — the message always says--buffer-sizeregardless.--parallelhas no short form, so it doesn't need that distinction, but-Sstill does; not touched here.Testing
--parallel=Xand--parallel X(space and=forms) for0, negative, non-numeric, empty, a suffix, and in-range valid values: 20/21 match; the one that doesn't (an overflowing value) is the deliberate scope boundary above, confirmed GNU itself doesn't error there while uutils does (by design, to avoid the hang).test_parallel_invalidfrom a bare exit-code check to exact GNU-matching messages, plus new cases for negative, empty, a suffix, and the space-separated negative form; verified to fail without the fix.cargo test --features sort --test tests -- test_sort: 211 passed, 0 failed (210 pre-existing — 1 strengthened, not deleted).moz-fluent-lintonsrc/uu/sort/locales: no errors.cargo fmt --checkandcargo clippy -p uu_sort --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.