From c5c165b4f30943b08a6f28b6b7dfc5ecdc384b78 Mon Sep 17 00:00:00 2001 From: Oli Lalonde Date: Mon, 11 Jul 2022 23:57:07 +0300 Subject: [PATCH] Expose the `.info` field --- src/lib.rs | 9 ++++++++- src/scanner.rs | 4 ++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index ae95e0f..40e33c8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -116,6 +116,13 @@ key1:a2 "; assert!(YamlLoader::load_from_str(s).is_err()); assert!(try_fail(s).is_err()); + assert_eq!( + try_fail(s).unwrap_err().info(), + "mapping values are not allowed in this context" + ); + assert_eq!( + try_fail(s).unwrap_err().to_string(), + "mapping values are not allowed in this context at line 4 column 4" + ); } - } diff --git a/src/scanner.rs b/src/scanner.rs index a8659a8..a11aac8 100644 --- a/src/scanner.rs +++ b/src/scanner.rs @@ -60,6 +60,10 @@ impl ScanError { pub fn marker(&self) -> &Marker { &self.mark } + + pub fn info(&self) -> &str { + self.info.as_ref() + } } impl Error for ScanError {