From b825e4cb42884cea3a7e8bf0ff74183a326f5d1b Mon Sep 17 00:00:00 2001 From: HampusM Date: Sat, 4 Mar 2023 12:41:02 +0100 Subject: refactor: improve parsing error message --- src/lib.rs | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index fddc1fb..f1e15cb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -87,8 +87,18 @@ impl ReferenceEntry let function_ref_content = function_file.contents(); let mut parser = Parser::new(function_ref_content); - - let root_elements = parser.parse()?; + let root_elements = + parser + .parse() + .map_err(|err| ReferenceEntryError::ParsingFailed { + source: err, + entry_name: function_file + .path() + .file_stem() + .unwrap_or_else(|| OsStr::new("(unknown)")) + .to_string_lossy() + .to_string(), + })?; ReferenceEntry::from_elements(&root_elements).map_err(|err| { ReferenceEntryError::Invalid { @@ -189,8 +199,16 @@ pub enum ReferenceEntryError }, /// Parsing failed. - #[error("Parsing failed")] - ParsingFailed(#[from] ParserError), + #[error("Failed to parse reference entry '{entry_name}'")] + ParsingFailed + { + /// Source error. + #[source] + source: ParserError, + + /// Name of the reference entry that couldn't be parsed. + entry_name: String, + }, } /// Error for when a reference entry is invalid. -- cgit v1.2.3-18-g5258