From f690d3d2869d93dec93aea4e17ea61fd0a907d51 Mon Sep 17 00:00:00 2001 From: p6nj Date: Thu, 31 Oct 2024 14:42:56 -0400 Subject: [PATCH] better sheet error display --- src/bng/score.rs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/bng/score.rs b/src/bng/score.rs index de6de55..7d9be29 100644 --- a/src/bng/score.rs +++ b/src/bng/score.rs @@ -45,18 +45,18 @@ enum AtomsSerializeError { fn nom_err_message(e: nom::Err>) -> String { match e { - nom::Err::Incomplete(needed) => todo!(), - nom::Err::Error(e) => format!( - "got error code {code:#?} at character n°{charn} (after \"{before}\")", - code = e.code, - charn = e.input.len() + 1, - before = &e.input[e.input.len() - - option_env!("SHEET_BACKTRACE") - .and_then(|s| s.parse().ok()) - .unwrap_or(10usize) - + 1..] + nom::Err::Incomplete(needed) => format!( + "input is incomplete, needed {} byte(s) more", + match needed { + nom::Needed::Unknown => "?".to_string(), + nom::Needed::Size(s) => s.to_string(), + } + ), + nom::Err::Error(e) | nom::Err::Failure(e) => format!( + "got error code {code:#?} at \"{input}\"", + code = e.code, + input = e.input ), - nom::Err::Failure(e) => todo!(), } } @@ -127,7 +127,7 @@ impl<'de> Deserialize<'de> for Atoms { let x = all_consuming(terminated( many0(preceded(many0(one_of(" \t\r")), flat_atom_parser(¬es))), many0(alt((char('\t'), char(' '), char('\n'), char('\r')))), - ))(dbg!(&sheet)) + ))(&sheet) .map_err(nom_err_message) .map_err(AtomsSerializeError::Parsing) .map_err(de::Error::custom)