diff options
author | HampusM <hampus@hampusmat.com> | 2023-03-04 12:41:02 +0100 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2023-03-04 12:41:02 +0100 |
commit | b825e4cb42884cea3a7e8bf0ff74183a326f5d1b (patch) | |
tree | c2cbbd92ee814649550aa0784ed0ff11b8541b2a /src | |
parent | 36fba448f15a2a58ee5aeb384f78967eb1a622ff (diff) |
refactor: improve parsing error message
Diffstat (limited to 'src')
-rw-r--r-- | src/lib.rs | 26 |
1 files changed, 22 insertions, 4 deletions
@@ -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. |