color-backtrace 0.6.1

Colorful panic backtraces

color-backtrace MIT licensed Apache 2.0 licensed

A Rust library that makes panics a little less painful by nicely colorizing them and printing the relevant source snippets.

color-backtrace = { version = "0.6" }

To enable it, simply place this code somewhere in your app initialization code:


If you want to customize some settings, you can instead do:

use color_backtrace::{default_output_stream, BacktracePrinter};
BacktracePrinter::new().message("Custom message!").install(default_output_stream());


  • 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

Usage in tests

Unfortunately, defining custom init functions run before tests are started is currently not supported in Rust. Since initializing color-backtrace in each and every test is tedious even when wrapping it into a function, I recommended using the ctor crate for this.

Somewhere, preferably in your crate's main module, put the following code:

mod tests {
    use ctor::ctor;

    fn init_color_backtrace() {

You can also do this outside of a #[cfg(test)] section, in which case the panic handler is installed for both test and regular runs.