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 {