Skip to content

Commit

Permalink
Eric/return error instead (#895)
Browse files Browse the repository at this point in the history
* revert

* Don't try to be friendly when input looks terribly wrong

* Do not dump the input in case of a generic error as well

Co-authored-by: Lex Vorona <[email protected]>
  • Loading branch information
eric-capeprivacy and Lex Vorona authored Feb 28, 2022
1 parent 1eecf57 commit 57eccda
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions moose/src/textual/parsing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,7 @@ pub fn parallel_parse_computation(source: &str, chunks: usize) -> anyhow::Result
.map(|s| {
parse_operations::<VerboseError<&str>>(s)
.map(|t| t.1) // Dropping the remainder
.map_err(|e| {
friendly_error("Failed to parse computation", "base64 encoded model", e)
})
.map_err(|e| friendly_error("Failed to parse computation", source, e))
})
.collect();
let mut operations = Vec::new();
Expand Down Expand Up @@ -1027,10 +1025,17 @@ pub fn parse_bool<'a, E: 'a + ParseError<&'a str> + ContextError<&'a str>>(
///
/// Note that it binds the E in the parser to be a `VerboseError`.
fn friendly_error(message: &str, source: &str, e: nom::Err<VerboseError<&str>>) -> anyhow::Error {
if !source.contains('\n') {
return anyhow::anyhow!(
"{}. The input contains no line breaks, which usually indicates invalid format. {}",
message,
e
);
}
match e {
Failure(e) => anyhow::anyhow!("{}\n{}", message, convert_error(source, e)),
Error(e) => anyhow::anyhow!("{}\n{}", message, convert_error(source, e)),
_ => anyhow::anyhow!("{} {} due to {}", message, source, e),
_ => anyhow::anyhow!("{} due to {}", message, e),
}
}

Expand Down

0 comments on commit 57eccda

Please sign in to comment.