Skip to content

Rust backtraces in errors #1860

Description

@enomado

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions