Skip to content

Commit

Permalink
utils/errors: Track error source
Browse files Browse the repository at this point in the history
in calls to `fatal`, so we keep track of the location where the panic
really originates. Otherwise, any call to `fatal` will show the code in
`errors` as source, which of course isn't true.
Also change the error formatting and do not call `to_log` for fatal
errors anymore, because the panic is already logged and contains much
more information.
  • Loading branch information
har7an committed Sep 5, 2022
1 parent 9ccc72e commit aa7bfeb
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions zellij-utils/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ pub trait FatalError<T> {
/// # Panics
///
/// If the given result is an `Err` variant.
#[track_caller]
fn fatal(self) -> T;
}

Expand All @@ -162,17 +163,16 @@ fn discard_result<T>(_arg: anyhow::Result<T>) {}
impl<T> FatalError<T> for anyhow::Result<T> {
fn non_fatal(self) {
if self.is_err() {
discard_result(self.context("A non-fatal error occured").to_log());
discard_result(self.context("a non-fatal error occured").to_log());
}
}

fn fatal(self) -> T {
if let Ok(val) = self {
val
} else {
self.context("A fatal error occured")
.to_log()
.expect("A fatal error occured, program terminates")
self.context("a fatal error occured")
.expect("Program terminates")
}
}
}
Expand Down

0 comments on commit aa7bfeb

Please sign in to comment.