Skip to content

Commit

Permalink
Document btparse support
Browse files Browse the repository at this point in the history
  • Loading branch information
athre0z committed Feb 9, 2025
1 parent 0c0f296 commit 78237a7
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
60 changes: 60 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,72 @@ BacktracePrinter::new().message("Custom message!").install(default_output_stream
```

### Features

- Colorize backtraces to be easier on the eyes
- Show source snippets if source files are found on disk
- Print frames of application code vs dependencies in different color
- Hide all the frames after the panic was already initiated
- Hide language runtime initialization frames

### Reducing transitive dependencies

It is possible to use the alternative [`btparse`] backtrace capturing backend
instead of the default route that links [`backtrace`]:

```
[dependencies]
color-backtrace = {
version = "0.6",
default-features = false,
features = ["use-btparse-crate"],
}
```

This reduces the number of transitive dependencies from around 12 to just 2. So
why isn't this the default, you may ask? There's a stability tradeoff here:
`btparse` relies on the **undocumented and unstable** `std::fmt::Debug`
implementation of `std::backtrace::Backtrace` to remain unchanged. As of writing,
this has been untouched for 4+ years, but there's no *guarantee* that it will
always work.

[`btparse`]: https://github.com/yaahc/btparse
[`backtrace`]: https://github.com/rust-lang/backtrace-rs

<details>
<summary>Dependency tree with `use-backtrace-crate` (default)</summary>

```
$ cargo tree
color-backtrace v0.6.1 (/Users/ath/Development/color-backtrace)
├── backtrace v0.3.73
│ ├── addr2line v0.22.0
│ │ └── gimli v0.29.0
│ ├── cfg-if v1.0.0
│ ├── libc v0.2.155
│ ├── miniz_oxide v0.7.4
│ │ └── adler v1.0.2
│ ├── object v0.36.1
│ │ └── memchr v2.7.4
│ └── rustc-demangle v0.1.24
│ [build-dependencies]
│ └── cc v1.1.1
└── termcolor v1.4.1
```

</details>

<details>
<summary>Dependency tree with `use-btparse-crate`</summary>

```
$ cargo tree --no-default-features --features=use-btparse-crate
color-backtrace v0.6.1 (/Users/ath/Development/color-backtrace)
├── btparse v0.2.0 (https://github.com/yaahc/btparse.git?rev=54f9ddb8c7c8f8e034226fdcacab93cd76e1453b#54f9ddb8)
└── termcolor v1.4.1
```

</details>

### Usage in tests

Unfortunately, defining custom init functions run before tests are started is
Expand Down
5 changes: 4 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
//! dependencies (green).
//!
//! ### Screenshot
//! ![Screenshot](https://i.imgur.com/jLznHxp.png)
//!
//! ![Screenshot](https://i.imgur.com/yzp0KH6.png)
//!
//! ### Features
//!
//! - Colorize backtraces to be easier on the eyes
//! - Show source snippets if source files are found on disk
//! - Print frames of application code vs dependencies in different color
Expand All @@ -30,6 +32,7 @@
//! ```
//!
//! ### Controlling verbosity
//!
//! The default verbosity is configured via the `RUST_BACKTRACE` environment
//! variable. An unset `RUST_BACKTRACE` corresponds to
//! [minimal](Verbosity::Minimal), `RUST_BACKTRACE=1` to
Expand Down

0 comments on commit 78237a7

Please sign in to comment.