Skip to content

Commit

Permalink
update error display
Browse files Browse the repository at this point in the history
Signed-off-by: simonsan <14062932+simonsan@users.noreply.github.com>
  • Loading branch information
simonsan committed Nov 1, 2024
1 parent 17180a6 commit 125e7e2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
11 changes: 9 additions & 2 deletions crates/core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
use derive_more::derive::Display;
use smol_str::SmolStr;
use std::{
backtrace::Backtrace,
backtrace::{Backtrace, BacktraceStatus},
borrow::Cow,
convert::Into,
fmt::{self, Display},
Expand Down Expand Up @@ -265,7 +265,7 @@ impl Display for RusticError {
writeln!(f, "\nContext:")?;
self.context
.iter()
.try_for_each(|(key, value)| writeln!(f, "- {key}:\t{value}"))?;
.try_for_each(|(key, value)| writeln!(f, "- {key}: {value}"))?;
}

if let Some(cause) = &self.source {
Expand All @@ -284,6 +284,13 @@ impl Display for RusticError {
if let Some(backtrace) = &self.backtrace {
writeln!(f, "\nBacktrace:")?;
writeln!(f, "{backtrace}")?;

if backtrace.status() == BacktraceStatus::Disabled {
writeln!(
f,
"\nTo enable backtraces, set the RUST_BACKTRACE=\"1\" environment variable."
)?;
}
}

Ok(())
Expand Down
6 changes: 4 additions & 2 deletions crates/core/tests/snapshots/errors__error_display.snap
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ Thank you for helping us improve rustic!
Some additional details ...

Context:
- path: /path/to/file
- called: used s3 backend
- path: /path/to/file
- called: used s3 backend

Caused by:
Networking Error : (source: None)
Expand All @@ -39,3 +39,5 @@ Status: Permanent

Backtrace:
disabled backtrace

To enable backtraces, set the RUST_BACKTRACE="1" environment variable.

0 comments on commit 125e7e2

Please sign in to comment.