Skip to content

Commit

Permalink
feat(s3s-test): print backtrace
Browse files Browse the repository at this point in the history
  • Loading branch information
Nugine committed Oct 22, 2024
1 parent e5a42c5 commit 3ca5170
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ resolver = "2"
edition = "2021"
repository = "https://github.com/Nugine/s3s"
license = "Apache-2.0"

[profile.release]
debug = "line-tables-only"
1 change: 1 addition & 0 deletions crates/s3s-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ indexmap = "2.6.0"
colored = "2.1.0"
regex = "1.11.0"
nugine-rust-utils = "0.3.1"
backtrace = "0.3.74"

[dependencies.aws-config]
version = "1.5.8"
Expand Down
15 changes: 15 additions & 0 deletions crates/s3s-test/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::env;
use std::fmt;

pub type Result<T = (), E = Failed> = std::result::Result<T, E>;
Expand All @@ -12,6 +13,20 @@ where
E: std::error::Error + Send + Sync + 'static,
{
fn from(source: E) -> Self {
if env::var("RUST_BACKTRACE").is_ok() {
eprintln!("Failed: {source}");
eprintln!("Backtrace:\n");
backtrace::trace(|frame| {
backtrace::resolve_frame(frame, |symbol| {
if let (Some(name), Some(filename), Some(colno)) = (symbol.name(), symbol.filename(), symbol.colno()) {
if filename.components().any(|c| c.as_os_str().to_str() == Some("s3s")) {
eprintln!("{name}\n at {}:{colno}\n", filename.display());
}
}
});
true
});
}
Self {
source: Some(Box::new(source)),
}
Expand Down

0 comments on commit 3ca5170

Please sign in to comment.