Radish alpha
h
rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5
Radicle Heartwood Protocol & Stack
Radicle
Git
Improve radicle-node panics
Merged fintohaps opened 9 months ago

To better help debugging when things go wrong after radicle-node crashes, RUST_BACKTRACE is registered in the main. According to this StackOverflow answer, this should not affect performance

Registers a panic handler to provide nicer information when the radicle-node panics. This partly inspired by a suggestion from a contributor and provided a link to their approach1.

1

https://github.com/pragma-org/amaru/blob/41ba1c26f82c813dfd052f9bc2adeb55dcd5957c/crates/amaru/src/bin/amaru/panic.rs#L17

1 file changed +9 -5 0aaa81f8 54fd8c40
modified crates/radicle-node/src/main.rs
@@ -131,12 +131,16 @@ fn execute() -> anyhow::Result<()> {
}

fn main() {
+
    // If `RUST_BACKTRACE` does not have a value, then we set it to capture
+
    // backtraces for better debugging, otherwise we keep the environments
+
    // value.
+
    const RUST_BACKTRACE: &str = "RUST_BACKTRACE";
+
    if std::env::var_os(RUST_BACKTRACE).is_none() {
+
        std::env::set_var(RUST_BACKTRACE, "1");
+
    }
+

    if let Err(err) = execute() {
-
        if log::log_enabled!(target: "node", log::Level::Error) {
-
            log::error!(target: "node", "Fatal: {err:#}");
-
        } else {
-
            eprintln!("Error: {err:#}");
-
        }
+
        log::error!(target: "node", "{err:#}");
        process::exit(1);
    }
}