Skip to content

Commit

Permalink
core: replace color-backtrace with color-eyre
Browse files Browse the repository at this point in the history
This begins a general migration to `eyre` for error handling:

https://github.com/yaahc/color-eyre
  • Loading branch information
tarcieri committed Dec 28, 2020
1 parent 5a462a7 commit 44c4be9
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 29 deletions.
47 changes: 30 additions & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ arc-swap = { version = "1", optional = true }
backtrace = "0.3"
canonical-path = "2"
chrono = { version = "0.4", optional = true, features = ["serde"] }
color-backtrace = { version = "0.5", optional = true, default-features = false }
color-eyre = { version = "0.5", optional = true, default-features = false }
fs-err = "2"
gumdrop = { version = "0.7", optional = true }
once_cell = "1.4"
Expand Down Expand Up @@ -65,6 +65,6 @@ config = [
trace = ["tracing", "tracing-log", "tracing-subscriber"]
options = ["gumdrop"]
secrets = ["secrecy"]
terminal = ["color-backtrace", "termcolor"]
terminal = ["color-eyre", "termcolor"]
testing = ["regex", "wait-timeout"]
time = ["chrono"]
14 changes: 4 additions & 10 deletions core/src/terminal/component.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,24 @@
//! Terminal component
use crate::Component;
use std::fmt;
use termcolor::ColorChoice;

/// Abscissa terminal subsystem component
#[derive(Component)]
#[derive(Component, Debug)]
#[component(core)]
pub struct Terminal {}

impl Terminal {
/// Create a new `TerminalComponent` with the given `ColorChoice`
/// Create a new [`Terminal`] component with the given [`ColorChoice`]
pub fn new(color_choice: ColorChoice) -> Terminal {
// TODO(tarcieri): handle terminal reinit (without panicking)
super::init(color_choice);

if color_choice != ColorChoice::Never {
color_backtrace::install();
// TODO(tarcieri): avoid panicking here
color_eyre::install().expect("couldn't install color-eyre");
}

Self {}
}
}

impl fmt::Debug for Terminal {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "TerminalComponent {{ stdout, stderr }}")
}
}

0 comments on commit 44c4be9

Please sign in to comment.