From 6a25d9ddd324747635053da64383ff4943ba1c79 Mon Sep 17 00:00:00 2001 From: Gaston Zanitti Date: Tue, 10 Oct 2023 13:42:38 -0300 Subject: [PATCH] Better error during parsing. Issue #82 --- etk-asm/src/ingest.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/etk-asm/src/ingest.rs b/etk-asm/src/ingest.rs index bc5e4bfd..5d969f79 100644 --- a/etk-asm/src/ingest.rs +++ b/etk-asm/src/ingest.rs @@ -51,13 +51,15 @@ mod error { }, /// An error that occurred while parsing a file. - #[snafu(context(false))] #[non_exhaustive] - #[snafu(display("parsing failed"))] + #[snafu(display("parsing failed on path `{}`", path.to_string_lossy()))] Parse { /// The underlying source of this error. #[snafu(backtrace)] source: ParseError, + + /// The location of the error. + path: PathBuf, }, /// An error that occurred while assembling a file. @@ -305,7 +307,9 @@ where } fn preprocess(&mut self, program: &mut Program, src: &str) -> Result, Error> { - let nodes = parse_asm(src)?; + let nodes = parse_asm(src).context(error::Parse { + path: program.sources.last().unwrap().clone(), + })?; let mut raws = Vec::new(); for node in nodes { match node {