Skip to content

Commit

Permalink
Output errors on a single line if backtraces are disabled (#1514)
Browse files Browse the repository at this point in the history
* Output errors on a single line if ANSI output is disabled

* Add changelog entry

* Use published version of `oneline-eyre`

* Use oneline logs if RUST_BACKTRACE is unset, set to 0 or empty

* Use colored logs only if ANSI output is enabled

* Use value of RUST_BACKTRACE at runtime instead of compile time

* Simplify code

* Use single-line errors if backtraces are disabled even with a tty
  • Loading branch information
romac authored Nov 16, 2021
1 parent 071f609 commit e8cb03a
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Output errors on a single line if ANSI output is disabled
([#1515](https://github.com/informalsystems/ibc-rs/issues/1515))
10 changes: 10 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions relayer-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ tracing = "0.1.29"
tracing-subscriber = { version = "0.3.1", features = ["fmt", "env-filter", "json"]}
eyre = "0.6.5"
color-eyre = "0.5"
oneline-eyre = "0.1"
futures = "0.3.17"
toml = "0.5.8"
serde_derive = "1.0.116"
Expand Down
28 changes: 24 additions & 4 deletions relayer-cli/src/bin/hermes/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,31 @@
use ibc_relayer_cli::application::APPLICATION;
use ibc_relayer_cli::components::enable_ansi;

/// Boot Cli
fn main() -> eyre::Result<()> {
if enable_ansi() {
color_eyre::install()?;
}
install_error_reporter()?;

abscissa_core::boot(&APPLICATION);
}

fn install_error_reporter() -> eyre::Result<()> {
if !backtrace_enabled() {
// If backtraces are disabled, display errors in single line.
oneline_eyre::install()
} else if enable_ansi() {
// Else, if backtraces are enabled and we are in a terminal
// supporting color, display full error logs in color.
color_eyre::install()
} else {
// Otherwise, backtraces are enabled and we are piping to logs, so use the
// default error report handler, which displays multiline errors
// without color.
Ok(())
}
}

fn backtrace_enabled() -> bool {
match std::env::var("RUST_BACKTRACE").as_deref() {
Ok("" | "0") | Err(_) => false,
Ok(_) => true,
}
}

0 comments on commit e8cb03a

Please sign in to comment.