From 1f29aaaf7ae460f58854e4277f4f4cb70abc7224 Mon Sep 17 00:00:00 2001 From: Huck Boles Date: Tue, 23 May 2023 20:56:12 -0500 Subject: [PATCH] refactored: added filename to parser errors --- src/error.rs | 5 ++--- src/metafile/file.rs | 10 ++++++++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/error.rs b/src/error.rs index c11f25b..4f82158 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,4 +1,3 @@ -use crate::Rule; use thiserror::Error; #[derive(Error, Debug)] @@ -25,13 +24,13 @@ pub enum MetaError { UndefinedDefault { pattern: String, path: String }, #[error("the parser cannot resolve this input: {input}")] UnreachableRule { input: String }, + #[error("{file}\n{error}")] + ParserError { file: String, error: String }, #[error(transparent)] MetaError(#[from] Box), #[error(transparent)] PandocError(#[from] pandoc::PandocError), #[error(transparent)] - ParserError(#[from] pest::error::Error), - #[error(transparent)] Other(#[from] eyre::Error), } diff --git a/src/metafile/file.rs b/src/metafile/file.rs index 7f8e70a..b664b09 100644 --- a/src/metafile/file.rs +++ b/src/metafile/file.rs @@ -45,7 +45,10 @@ impl<'a> MetaFile<'a> { } }; - let mut metafile = parse_string(str, opts).map_err(MetaError::from)?; + let mut metafile = parse_string(str, opts).map_err(|e| MetaError::ParserError { + file: path.to_string_lossy().to_string(), + error: e.to_string(), + })?; metafile.path = path; Ok(metafile) @@ -63,7 +66,10 @@ impl<'a> MetaFile<'a> { let html = self.to_html().map_err(MetaError::from)?; let pattern = self.get_pattern("base").map_err(MetaError::from)?; - let mut base = crate::parse_string(pattern, self.opts).map_err(MetaError::from)?; + let mut base = parse_string(pattern, self.opts).map_err(|e| MetaError::ParserError { + file: self.path.to_string_lossy().to_string(), + error: e.to_string(), + })?; base.merge(self); base.patterns.insert(Scope::into_global("SOURCE"), html); -- 2.45.2