Commit 3ca5170b authored by Nugine's avatar Nugine
Browse files

feat(s3s-test): print backtrace

parent e5a42c52
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -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 −0
Original line number Diff line number Diff line
@@ -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"
+15 −0
Original line number Diff line number Diff line
use std::env;
use std::fmt;

pub type Result<T = (), E = Failed> = std::result::Result<T, E>;
@@ -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)),
        }