-
Notifications
You must be signed in to change notification settings - Fork 837
Description
Having some experience writing parsers with nom, I think I now understand what I’m missing.
I want maximal, full backtraces, captured with Backtrace::capture()
. Since parsers are combinators, they would show the exact place where the problem occurred across the whole stack.
Basically, I often try to figure out where a problem happened by replacing ?
with .unwrap()
:
let (i, device) = parse_go(i)?;
let (i, _) = parse_brr(i)?;
becomes:
let (i, device) = parse_go(i).unwrap();
let (i, _) = parse_brr(i).unwrap();
Maybe there could exist something like:
let (i, _) = parse_brr(i).catch_backtrace_if_error()?;
that would work in debug mode? This would save hours of writing extra parsers in situations where the document format is unspecified, and the parser fails on the syntax of a new contractor, for example.
I’ll start my own experiments, but it seems the error types are rigidly fixed and there’s not much to add besides &str
. Has anyone tried doing this already?