From da721182553c7f3e5dbb470062cbbc03a84b45f8 Mon Sep 17 00:00:00 2001 From: Alain Emilia Anna Zscheile Date: Mon, 2 Dec 2024 22:53:22 +0100 Subject: [PATCH] fix(specctra): return error when point fails to parse first f64 --- src/specctra/read.rs | 2 +- src/specctra/structure.rs | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/specctra/read.rs b/src/specctra/read.rs index f19e92a..28c2456 100644 --- a/src/specctra/read.rs +++ b/src/specctra/read.rs @@ -35,7 +35,7 @@ pub struct ParseErrorContext { pub struct InputToken { pub token: ListToken, - context: (usize, usize), + pub context: (usize, usize), } impl InputToken { diff --git a/src/specctra/structure.rs b/src/specctra/structure.rs index 7944c2a..cc56ebb 100644 --- a/src/specctra/structure.rs +++ b/src/specctra/structure.rs @@ -399,7 +399,9 @@ impl ReadDsn for Vec { loop { let input = tokenizer.consume_token()?; if let ListToken::Leaf { value: ref x } = input.token { - let x = x.parse::().unwrap(); + let x = x + .parse::() + .map_err(|_| ParseError::Expected("f64").add_context(input.context))?; let y = tokenizer.read_value::()?; array.push(Point { x, y }); } else { @@ -415,7 +417,9 @@ impl ReadDsn for Option { fn read_dsn(tokenizer: &mut ListTokenizer) -> Result { let input = tokenizer.consume_token()?; if let ListToken::Leaf { value: ref x } = input.token { - let x = x.parse::().unwrap(); + let x = x + .parse::() + .map_err(|_| ParseError::Expected("f64").add_context(input.context))?; let y = tokenizer.read_value::()?; Ok(Some(Point { x, y })) } else {