diff options
| author | Nixon Enraght-Moony <nixon.emoony@gmail.com> | 2022-02-04 19:47:34 +0000 |
|---|---|---|
| committer | Nixon Enraght-Moony <nixon.emoony@gmail.com> | 2022-02-09 16:10:58 +0000 |
| commit | 2d0bb0d4b9b072ebd2cb78c71f3ca3a706b5d12e (patch) | |
| tree | ed225384b5bc6069fcc7dce87de96e8a987d6597 | |
| parent | 4e8fb743ccbec27344b2dd42de7057f41d4ebfdd (diff) | |
| download | rust-2d0bb0d4b9b072ebd2cb78c71f3ca3a706b5d12e.tar.gz rust-2d0bb0d4b9b072ebd2cb78c71f3ca3a706b5d12e.zip | |
jsondocck: Improved error messages for invalid json value and failed @count check
| -rw-r--r-- | src/tools/jsondocck/src/main.rs | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/src/tools/jsondocck/src/main.rs b/src/tools/jsondocck/src/main.rs index b8ea10f3d22..d0f476955e1 100644 --- a/src/tools/jsondocck/src/main.rs +++ b/src/tools/jsondocck/src/main.rs @@ -231,7 +231,21 @@ fn check_command(command: Command, cache: &mut Cache) -> Result<(), CkError> { let val = cache.get_value(&command.args[0])?; let results = select(&val, &command.args[1]).unwrap(); - results.len() == expected + let eq = results.len() == expected; + if !command.negated && !eq { + return Err(CkError::FailedCheck( + format!( + "`{}` matched to `{:?}` with length {}, but expected length {}", + &command.args[1], + results, + results.len(), + expected + ), + command, + )); + } else { + eq + } } CommandKind::Is => { // @has <path> <jsonpath> <value> = check *exactly one* item matched by path, and it equals value @@ -317,6 +331,6 @@ fn string_to_value<'a>(s: &str, cache: &'a Cache) -> Cow<'a, Value> { panic!("No variable: `{}`. Current state: `{:?}`", &s[1..], cache.variables) })) } else { - Cow::Owned(serde_json::from_str(s).unwrap()) + Cow::Owned(serde_json::from_str(s).expect(&format!("Cannot convert `{}` to json", s))) } } |
