From 85f9735978433c9d49a24f51fa76b28f45beeb7c Mon Sep 17 00:00:00 2001 From: Michal 'vorner' Vaner Date: Sun, 30 Dec 2018 19:06:28 +0100 Subject: 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. --- tests/errors.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'tests') 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::().unwrap_err(); + if let ConfigError::Type { key: Some(path), .. } = e { + assert_eq!(path, "inner.test"); + } else { + panic!("Wrong error {:?}", e); + } +} -- cgit v1.2.3