mknod: match GNU's error for a bad MAJOR/MINOR device number - #14316
Closed
arbelonson-source wants to merge 1 commit into
Closed
mknod: match GNU's error for a bad MAJOR/MINOR device number#14316arbelonson-source wants to merge 1 commit into
arbelonson-source wants to merge 1 commit into
Conversation
MAJOR and MINOR validated their values with clap's own
value_parser!(u32), so an unparseable or overflowing value produced
clap's own generic wording ('invalid value ... invalid digit found in
string' / '... is not in 0..=4294967295') instead of GNU's uniform
'invalid major/minor device number: ...'.
Resolve the value by hand: parse as u32, reject anything that doesn't
fit (unparseable or overflowing) with GNU's wording, distinguishing
which of the two operands it was for. A negative value passed as its
own positional argument (e.g. 'mknod f c -5 5') is left as clap's own
'unexpected argument' rejection: GNU's own getopt also rejects it as
an unrecognized OPTION ('invalid option -- '5'') rather than an
invalid device number, a different and much deeper mismatch (clap vs.
getopt's own unknown-argument handling, not specific to this option)
that's out of scope for this fix.
AI-assisted-by: Claude Opus 5, via Claude Code
Contributor
|
clap's error message is better at here because it provides what you should do too. |
Contributor
|
i think our error msg is better, so, let's keep it. |
|
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.
What
MAJORandMINORvalidate their values with clap's ownvalue_parser!(u32), so an unparseable or overflowing value producesclap's own generic wording instead of GNU's:
Fix
Resolve the value by hand: parse as
u32, reject anything thatdoesn't fit (unparseable or overflowing) with GNU's wording,
distinguishing which of the two operands (major/minor) it was for --
same wording shape as
ptx --gap-size/--width(#14315), no separate"value too large" case needed since GNU's own message doesn't
distinguish overflow from any other bad value here either.
A negative value passed as its own positional argument (e.g.
mknod f c -5 5) is deliberately left alone, still reported as clap's own"unexpected argument" rejection: GNU's own
getoptalso rejects it,but as an unrecognized option (
invalid option -- '5') ratherthan an invalid device number -- a different and much deeper mismatch
(clap's vs. getopt's own unknown-argument handling in general, not
anything specific to this option) that's out of scope for this fix.
Testing
cargo test --features mknod -p uu_mknod/ fulltests/by-util/test_mknod.rssuite: 14 passed, 0 failed.LC_ALL=C(viasudo, since device-node creation requires it).cargo clippy -p uu_mknod --all-targets -- -D warningsandcargo fmt --check: clean.This PR was written with AI assistance (Claude Opus 5, via Claude Code). I've tested the changes but please review the code carefully.