summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2023-03-04 12:41:02 +0100
committerHampusM <hampus@hampusmat.com>2023-03-04 12:41:02 +0100
commitb825e4cb42884cea3a7e8bf0ff74183a326f5d1b (patch)
treec2cbbd92ee814649550aa0784ed0ff11b8541b2a
parent36fba448f15a2a58ee5aeb384f78967eb1a622ff (diff)
refactor: improve parsing error message
-rw-r--r--src/lib.rs26
1 files 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.