-
Notifications
You must be signed in to change notification settings - Fork 1.7k
CLI: Reject invalid argument values rather than ignore them #6723
Conversation
parity/cli/usage.rs
Outdated
Err(clap_error @ ClapError { kind: ClapErrorKind::ValueValidation, .. }) => { | ||
return Err(clap_error); | ||
}, | ||
_ => $e |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it would be better to unwrap the value here rather then calling ok()
later.
match $e {
Err(clap_error @ ClapError { kind: ClapErrorKind::ValueValidation, .. }) => {
return Err(clap_error);
},
Ok(e) => e
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the reason to ignore errors other than ClapErrorKind::ValueValidation
btw?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@arkpar the clap macro value_t!
(whose result I feed into the return_if_parse_error!
macro) yields a Result
; the error can be either ClapErrorKind::ArgumentNotFound
or ClapErrorKind::ValueValidation
. If it's ArgumentNotFound
then the value of the argument in the struct should be None
.
@debris I thought about it but figured it'd be better if the macro didn't convert to Option for separation of concern, but I agree it'd be better for DRY. $e
can be either ClapErrorKind::ValueValidation
error, or ClapErrorKind::ArgumentNotFound
error, or Ok(...)
; in the two latter cases this is normal behaviour and we want to convert it to Option; I guess the following would be good?
match $e {
Err(clap_error @ ClapError { kind: ClapErrorKind::ValueValidation, .. }) => {
return Err(clap_error);
},
_ => $e.ok()
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, just describe it in the comment ;)
* CLI: Reject invalid argument values rather than ignore them * Fix grumbles
Previously (since the CLI port to clap), passing invalid values (e.g. providing a string value to an argument that expects a u32) was failing silently and was processed just like if the argument hadn't been entered.
Now, Parity explicitly refuses to launch if Clap cannot parse the value into the expected type.