node: register backtrace

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

[so]: https://stackoverflow.com/questions/29421727/how-much-overhead-does-rust-backtrace-1-have/45402131#45402131
This commit is contained in:
Fintan Halpenny 2025-07-28 10:30:45 +01:00
parent 0aaa81f82a
commit 174792813a
1 changed files with 8 additions and 0 deletions

View File

@ -131,6 +131,14 @@ 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:#}");