From 006b99bdac13cec71131f627c3d6dd0722d3284a Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Fri, 24 Apr 2026 22:44:19 -0400 Subject: [PATCH] bin: enable panic backtraces by default stderr is redirected to ~/.consciousness/logs/tui-stderr.log via redirect_stderr_to_pipe(), but the default panic hook checks RUST_BACKTRACE before printing the trace; without the env var the log only catches the "note: run with \`RUST_BACKTRACE=full\`" tail and the actual frames are dropped. Set RUST_BACKTRACE=1 programmatically before any other thread spawns so the log captures the trace by default. Existing user-set value is respected so callers can still opt into "full" if they want. Co-Authored-By: Proof of Concept --- src/bin/consciousness.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/bin/consciousness.rs b/src/bin/consciousness.rs index 2fcfebf..61d28e1 100644 --- a/src/bin/consciousness.rs +++ b/src/bin/consciousness.rs @@ -2,6 +2,17 @@ #![warn(unreachable_pub)] fn main() { + // Force the default panic hook to print a backtrace. stderr is + // already redirected to a daemon log; without this the hook obeys + // RUST_BACKTRACE (unset by default), so the log only shows the + // "note: run with `RUST_BACKTRACE=full`" tail and the actual + // frames are lost. + // + // SAFETY: called before any other thread is spawned, so no + // concurrent env reader can race. + if std::env::var_os("RUST_BACKTRACE").is_none() { + unsafe { std::env::set_var("RUST_BACKTRACE", "1"); } + } std::panic::set_backtrace_style(std::panic::BacktraceStyle::Short); consciousness::user::main() }