Skip to content

Commit d578c05

Browse files
committed
feat(debug): log anyhow backtrace on error with RUST_[LIB_]BACKTRACE=1
With `RUST_[LIB_]BACKTRACE=1` anyhow captures backtraces to the origin of an error chain. The backtrace can then be accessed via `anyhow::Error::backtrace`, which returns a `Display`able type (`std::backtrace::Backtrace` at our version of rust). To avoid being too noisy and allow targeted enabling of backtraces, the backtrace is logged with `debug!` under the `flox::backtrace` target. Unfortunately, `thiserror` supports backtraces only when compiled with rust nightly [1][2], on account of being blocked by the stabilization of `error_generic_member_access` [3]. [1]: <dtolnay/thiserror#390> [2]: <dtolnay/thiserror#387> [3]: <rust-lang/rust#99301>
1 parent 276dab5 commit d578c05

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

cli/flox/src/main.rs

+4
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ fn main() -> ExitCode {
157157

158158
if let Some(message) = message {
159159
message::error(message);
160+
debug!(target: "flox::backtrace", "{}", e.backtrace());
161+
160162
return ExitCode::from(1);
161163
}
162164

@@ -168,6 +170,8 @@ fn main() -> ExitCode {
168170

169171
message::error(err_str);
170172

173+
debug!(target: "flox::backtrace", "{}", e.backtrace());
174+
171175
ExitCode::from(1)
172176
},
173177
};

0 commit comments

Comments
 (0)