-
Notifications
You must be signed in to change notification settings - Fork 352
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Output errors on a single line if backtraces are disabled #1514
Conversation
231f908
to
9d6ca31
Compare
This feels a bit overly restrictive that it would be impossible to capture full back trace in log files if it is ever needed. Should we only use the one-line error reporter if |
9d6ca31
to
ca0cdba
Compare
relayer-cli/src/bin/hermes/main.rs
Outdated
color_eyre::install()?; | ||
} | ||
|
||
abscissa_core::boot(&APPLICATION); | ||
} | ||
|
||
fn compact_logs() -> bool { | ||
matches!(std::env::var("RUST_BACKTRACE").as_deref(), Ok("" | "0")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think in this case if RUST_BACKTRACE
is not set, the error case Err(_)
will return false when it should be true.
This should be clearer with comment explaining what should happen in different branches:
fn main() -> eyre::Result<()> {
install_error_reporter()?;
abscissa_core::boot(&APPLICATION);
}
fn install_error_reporter() -> eyre::Result<()> {
if enable_ansi() {
// If we are in a terminal supporting color, display
// full error logs in color
color_eyre::install()?;
} else if !backtrace_enabled() {
// Else if we are piping logs to file and backtrace is *not* enabled,
// display errors in single line.
oneline_eyre::install()?;
} else {
// Else backtrace is 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,
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, thanks! Shouldn't we invert the first two branches? ie. if backtraces are not enabled, we use one-line logs, otherwise if there is a tty we use colors, else we use the default reporter.
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(())
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it depends on what we want the default behavior to be. Most of the time the relayer will run without RUST_BACKTRACE
set, even for terminal cases. Do we want those to display one-line errors as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most of the time the relayer will be piping to logs. So one line logs should be the default case.
…stems#1514) * 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
Closes: #1529
Description
This uses our fork of
simple-eyre
, calledoneline-eyre
.Output with
RUST_BACKTRACE = "full"
:Output without
RUST_BACKTRACE
unset or set to"0"
or""
:For contributor use:
unclog
.docs/
) and code comments.Files changed
in the Github PR explorer.