Skip to content

sort: report an invalid --parallel value as GNU does - #15184

Merged
sylvestre merged 3 commits into
uutils:mainfrom
NdekoCode:sort-parallel-diagnostics
Oct 22, 2026
Merged

sylvestre merged 3 commits into
uutils:mainfrom
NdekoCode:sort-parallel-diagnostics

Conversation

@NdekoCode

Copy link
Copy Markdown
Contributor

The value of --parallel was parsed by clap as a number from 1 up, so a bad one came out as invalid value '0' for '--parallel <NUM_THREADS>': 0 is not in 1..18446744073709551615. GNU 9.12 says number in parallel must be nonzero, invalid --parallel argument 'x' (also for -1 and an empty value) and invalid suffix in --parallel argument '1x', with exit status 2, and accepts a leading +.

sort now parses the value itself, with the invalid --X argument, invalid suffix and too large messages it already has for its other numeric options. A value that does not fit in 64 bits gets --parallel argument '…' too large, where GNU fails on the allocation with memory exhausted. Checked against GNU 9.12; the sort suite passes. Part of what sort/sort.pl from #14705 checks.

Closes #15183.

@oech3

oech3 commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

We don't need to match errorr message with GNU. We can patch stderr of GnuTests if needed.
clap's provides more details generally.

Comment thread src/uu/sort/src/sort.rs Resolved
Comment thread tests/by-util/test_sort.rs Resolved
@NdekoCode

Copy link
Copy Markdown
Contributor Author

@oech3 sort.pl checks these two messages verbatim (--parallel -1 and --parallel a, as separate args), and clap's u64 parser also refused --parallel=+2, which GNU accepts.

@NdekoCode
NdekoCode requested a review from sylvestre October 9, 2026 21:58
The value was parsed by clap as a number from 1 up, so a bad one came
out as "invalid value '0' for '--parallel <NUM_THREADS>': 0 is not in
1..18446744073709551615". GNU says "number in parallel must be
nonzero", "invalid --parallel argument 'x'" and "invalid suffix in
--parallel argument '1x'", and accepts a leading '+'.

Parse the value here, with the messages sort already has for its other
numeric options, and exit with status 2 as GNU does.
The parse sat inside the cfg(not(wasi)) block, so on wasi a bad value
was silently accepted and parse_parallel was dead code there. Also test
the empty value, and every value given as a separate argument, which is
how sort.pl passes it.
sort exits before reading it, and writing to it then fails on some targets.
@NdekoCode
NdekoCode force-pushed the sort-parallel-diagnostics branch from 1483ceb to 06b2b1e Compare October 20, 2026 19:34
@NdekoCode

NdekoCode commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor Author

@oech3, @sylvestre rebased on main. The invalid cases no longer pipe input: sort exits before reading it, and the write failed on some targets.

@sylvestre
sylvestre merged commit fede671 into uutils:main Oct 22, 2026
141 of 142 checks passed
@sylvestre

Copy link
Copy Markdown
Contributor

Thanks for your PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sort: an invalid --parallel value is reported by clap, not as GNU does

3 participants