1932: fix(errors): ensure that validation failure error message includes a newline r=CreepySkeleton a=pmarks



Co-authored-by: Patrick Marks <patrick@10xgenomics.com>
This commit is contained in:
bors[bot] 2020-05-17 17:11:56 +00:00 committed by GitHub
commit e747ec11ab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 0 deletions

View file

@ -851,6 +851,7 @@ impl Error {
} }
c.none(&format!(": {}", err))?; c.none(&format!(": {}", err))?;
try_help(&mut c)?;
Ok(Error { Ok(Error {
cause: format!( cause: format!(

View file

@ -17,3 +17,22 @@ fn both_validator_and_validator_os() {
) )
.try_get_matches_from(&["app", "1"]); .try_get_matches_from(&["app", "1"]);
} }
#[test]
fn test_validator_msg_newline() {
let res = App::new("test")
.arg(Arg::new("test").validator(|val| val.parse::<u32>().map_err(|e| e.to_string())))
.try_get_matches_from(&["app", "f"]);
assert!(res.is_err());
let err = res.unwrap_err();
assert_eq!(
err.cause,
"Invalid value for \'<test>\': invalid digit found in string"
);
// This message is the only thing that gets printed -- make sure it ends with a newline
let msg = format!("{}", err);
assert!(msg.ends_with('\n'));
}