Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
REVIEW: Actually print a backtrace on broken pipe
✗ CI failure Lorenz Leutgeb committed 23 days ago
commit 4e39faa51387363d128018303c7f3564d0727745
parent fd2e9636f26887d9d7af9ed9ce7f8112185072c8
1 failed (1 total) View logs
5 files changed +35 -20
modified Cargo.lock
@@ -3023,6 +3023,7 @@ name = "radicle-cli"
version = "0.20.0"
dependencies = [
 "anyhow",
+
 "backtrace",
 "chrono",
 "clap",
 "clap_complete",
modified Cargo.toml
@@ -20,6 +20,7 @@ rust-version = "1.85.0"

[workspace.dependencies]
amplify = { version = "4.0.0", default-features = false }
+
backtrace = "0.3.75"
bstr = "1.3"
bytes = "1.11.1"
chrono = { version = "0.4.26", default-features = false }
modified crates/radicle-cli/Cargo.toml
@@ -14,7 +14,7 @@ name = "rad"
path = "src/main.rs"

[features]
-
default = ["tor"]
+
default = ["backtrace", "tor"]
tor = ["radicle/tor"]

[dependencies]
@@ -59,10 +59,12 @@ zeroize = { workspace = true }

[target.'cfg(unix)'.dependencies]
shlex = { workspace = true }
+
backtrace = { workspace = true, optional = true }

[target.'cfg(windows)'.dependencies]
winsplit = { workspace = true }

+

[dev-dependencies]
pretty_assertions = { workspace = true }
radicle = { workspace = true, features = ["test"] }
modified crates/radicle-cli/src/main.rs
@@ -193,28 +193,39 @@ fn run(command: Command, ctx: impl term::Context) -> ! {
/// [`std::io::stderr`].
#[cfg(unix)]
fn handle_broken_pipe(info: &std::panic::PanicHookInfo<'_>) {
-
    if is_broken_pipe_panic(info) {
-
        if cfg!(debug_assertions) {
-
            let mut stderr = std::io::stderr().lock();
-
            writeln!(
-
                stderr,
-
                "SIGPIPE detected. Attempting to print 'PanicHookInfo::payload', before returning with exit code 0"
-
            )
-
            .ok();
-
            if let Some(payload) = info.payload().downcast_ref::<&str>() {
-
                writeln!(stderr, "{payload}").ok();
-
            } else if let Some(payload) = info.payload().downcast_ref::<String>() {
-
                writeln!(stderr, "{payload}").ok();
-
            } else {
-
                writeln!(
+
    if !is_broken_pipe_panic(info) {
+
        return;
+
    }
+

+
    if cfg!(debug_assertions) {
+
        let thread = std::thread::current();
+
        let thread = thread.name().unwrap_or("<unnamed>");
+

+
        let mut stderr = std::io::stderr().lock();
+

+
        match info.location() {
+
            Some(location) => {
+
                let _ = writeln!(
                    stderr,
-
                    "'PanicInfoHook::payload' could not be downcast to 'str' or 'String'"
-
                )
-
                .ok();
+
                    "broken pipe in thread '{thread}' at: {}:{}",
+
                    location.file(),
+
                    location.line(),
+
                );
+
            }
+
            None => {
+
                let _ = writeln!(stderr, "broken pipe in thread '{thread}'");
            }
        }
-
        process::exit(0);
+

+
        #[cfg(feature = "backtrace")]
+
        let backtrace = format!("{:?}", backtrace::Backtrace::new());
+

+
        #[cfg(not(feature = "backtrace"))]
+
        let backtrace = "(no backtrace available)";
+

+
        let _ = writeln!(stderr, "{backtrace}");
    }
+
    process::exit(0);
}

/// Check if any error in the [`anyhow::Error::chain`] of `err` is of kind
modified crates/radicle-node/Cargo.toml
@@ -16,7 +16,7 @@ test = ["radicle/test", "radicle-crypto/test", "radicle-crypto/cyphernet", "radi
tor = ["cyphernet/tor", "radicle/tor", "radicle-protocol/tor"]

[dependencies]
-
backtrace = { version = "0.3.75", optional = true }
+
backtrace = { workspace = true, optional = true }
bloomy = "1.2"
bytes = { workspace = true }
chrono = { workspace = true, features = ["clock"] }