7 unstable releases (3 breaking)
new 0.5.0 | Jan 10, 2025 |
---|---|
0.3.3 | Jan 2, 2025 |
0.2.2 | Sep 23, 2024 |
0.1.0 | Sep 21, 2024 |
#209 in Debugging
275 downloads per month
38KB
553 lines
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[^waffle],
and library users can ignore the the existence of this crate entirely[^waffle]. 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.
[^waffle]: Users will see this crate/types will be modified, minimally, when:
- Struct fields are public
- The necessary pkg field does not block any functionality. When derived it will be hidden.
- The error is an enum
- The macro only supports creating a struct that wraps the enum as transparently as possible.
- Direct implementation on an enum is possible, but likely pretty clunky.
The formatting is borrowed from from error-stack. Please see the contributors page for appropriate credit.
Example Output (source_line)
Generate with cd bare_err_tree/test_cases/std; cargo run --bin example
.
missed class
├─ at src/bin/example.rs:26:6
│
╰─▶ stayed in bed too long
├─ at src/bin/example.rs:18:57
│
├─▶ bed is comfortable
│
╰─▶ went to sleep at 2 A.M.
├─ at src/bin/example.rs:18:72
│
├─▶ finishing a project
│ │
│ ╰─▶ proving 1 == 2
│
├─▶ stressed about exams
│
╰─▶ playing video games
Example Output (source_line + tracing)
Generate with cd bare_err_tree/test_cases/trace; cargo run --bin trace_example
.
missed class
├─ at src/bin/trace_example.rs:46:6
│
╰─▶ stayed in bed too long
├─ at src/bin/trace_example.rs:35:57
│
├─ tracing frame 0 => trace_example::new with
│ bed_time=BedTime {
│ hour: 2,
│ reasons: [
│ FinishingProject(
│ ClassProject {
│ desc: "proving 1 == 2"
│ }
│ ),
│ ExamStressed,
│ PlayingGames
│ ]
│ }
│ _garbage=5
│ at src/bin/trace_example.rs:119
│
├─▶ bed is comfortable
│
╰─▶ went to sleep at 2 A.M.
├─ at src/bin/trace_example.rs:36:9
│
├─▶ finishing a project
│ │
│ ╰─▶ proving 1 == 2
│
├─▶ stressed about exams
│
╰─▶ playing video games
Dependencies
~0–510KB