bare_err_tree_proc

Crates.iobare_err_tree_proc
lib.rsbare_err_tree_proc
version0.2.3
sourcesrc
created_at2024-09-21 20:27:06.338355
updated_at2024-09-23 15:53:28.582331
descriptionDisplay errors as a formatted tree
homepage
repositoryhttps://github.com/Bennett-Petzold/bare_err_tree
max_upload_size
id1382450
size60,939
(Bennett-Petzold)

documentation

README

Crate Tests Docs

bare_err_tree

bare_err_tree is a no_std library to print a standard Error with a tree of sources.

Support for the extra information prints does not change the type or public API (besides a hidden field or deref). It is added via macro or manual implementation of the AsErrTree trait (see the docs for details). End users can then use tree_unwrap or print_tree to get better error output.

Unlike anyhow, eyre, or error-stack, the extra functionality does not require exposing a special type in a library's API. A library can use bare_err_tree for its errors without changing any types, and library users can ignore the the existence of this crate entirely. There is also support for including any implementor of Error in the tree with less information, so it works on top of std and other libraries.

The formatting is borrowed from from error-stack. Please see the contributors page for appropriate credit.

Example Output (source_line)

Generate with cd testing; cargo run --bin example.

missed class
├─ at testing/src/bin/example.rs:25:6
│
╰─▶ stayed in bed too long
    ├─ at testing/src/bin/example.rs:17:57
    │
    ├─▶ bed is comfortable
    │
    ╰─▶ went to sleep at 2 A.M.
        ├─ at testing/src/bin/example.rs:17:72
        │
        ├─▶ finishing a project
        │   │
        │   ╰─▶ proving 1 == 2
        │
        ├─▶ stressed about exams
        │
        ╰─▶ playing video games

Example Output (source_line + tracing)

Generate with cd testing_trace; cargo run --bin trace_example.

missed class
├─ at testing_trace/src/bin/trace_example.rs:44:6
│
├─ tracing frame 0 => trace_example::run_fatal
│        at testing_trace/src/bin/trace_example.rs:31
│
╰─▶ stayed in bed too long
    ├─ at testing_trace/src/bin/trace_example.rs:33:57
    │
    ├─ tracing frame 1 => trace_example::new with
    │    bed_time=BedTime {
    │      hour: 2,
    │      reasons: [
    │        FinishingProject(
    │          ClassProject {
    │            desc: "proving 1 == 2"
    │          }
    │        ),
    │        ExamStressed,
    │        PlayingGames
    │      ]
    │    }
    │    _garbage=5
    │        at testing_trace/src/bin/trace_example.rs:117
    ├─ 1 duplicate tracing frame(s): [0]
    │
    ├─▶ bed is comfortable
    │
    ╰─▶ went to sleep at 2 A.M.
        ├─ at testing_trace/src/bin/trace_example.rs:34:9
        │
        ├─ 1 duplicate tracing frame(s): [0]
        │
        ├─▶ finishing a project
        │   │
        │   ╰─▶ proving 1 == 2
        │
        ├─▶ stressed about exams
        │
        ╰─▶ playing video games

TODO

  • Clean up proc macro code
    • Add more internal documentation
    • Write tests to make sure the proc macro is fully correct
Commit count: 39

cargo fmt