diff options
author | Michal 'vorner' Vaner <vorner@vorner.cz> | 2018-12-30 19:06:28 +0100 |
---|---|---|
committer | Michal 'vorner' Vaner <vorner@vorner.cz> | 2018-12-30 19:06:28 +0100 |
commit | 85f9735978433c9d49a24f51fa76b28f45beeb7c (patch) | |
tree | 29c4d09169f08df2597f985efcfaf71267cc16e6 /tests/errors.rs | |
parent | 2eca1ad50c899f52c7a589105180f85817f94049 (diff) |
Tracking a path where an error happens during deserialization
Related to #83, but doesn't solve that specific problem :-(. That
specific error message ("missing field") comes from somewhere else than
this library.
Diffstat (limited to 'tests/errors.rs')
-rw-r--r-- | tests/errors.rs | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/errors.rs b/tests/errors.rs index fa2816e..030ae74 100644 --- a/tests/errors.rs +++ b/tests/errors.rs @@ -92,3 +92,28 @@ fn test_error_enum_de() { ); } +#[test] +fn error_with_path() { + #[derive(Debug, Deserialize)] + struct Inner { + test: i32, + } + + #[derive(Debug, Deserialize)] + struct Outer { + inner: Inner, + } + const CFG: &str = r#" +inner: + test: ABC +"#; + + let mut cfg = Config::new(); + cfg.merge(File::from_str(CFG, FileFormat::Yaml)).unwrap(); + let e = cfg.try_into::<Outer>().unwrap_err(); + if let ConfigError::Type { key: Some(path), .. } = e { + assert_eq!(path, "inner.test"); + } else { + panic!("Wrong error {:?}", e); + } +} |