From 3ca5170b59430c5aa86eb635b32a15dfdbcab757 Mon Sep 17 00:00:00 2001 From: Nugine Date: Tue, 22 Oct 2024 17:19:13 +0800 Subject: [PATCH] feat(s3s-test): print backtrace --- Cargo.toml | 3 +++ crates/s3s-test/Cargo.toml | 1 + crates/s3s-test/src/error.rs | 15 +++++++++++++++ 3 files changed, 19 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 0326cde9..26398557 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,3 +6,6 @@ resolver = "2" edition = "2021" repository = "https://github.com/Nugine/s3s" license = "Apache-2.0" + +[profile.release] +debug = "line-tables-only" diff --git a/crates/s3s-test/Cargo.toml b/crates/s3s-test/Cargo.toml index d27a5e54..8edc133d 100644 --- a/crates/s3s-test/Cargo.toml +++ b/crates/s3s-test/Cargo.toml @@ -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" diff --git a/crates/s3s-test/src/error.rs b/crates/s3s-test/src/error.rs index 8bee23e2..b709015c 100644 --- a/crates/s3s-test/src/error.rs +++ b/crates/s3s-test/src/error.rs @@ -1,3 +1,4 @@ +use std::env; use std::fmt; pub type Result = std::result::Result; @@ -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)), }