anyhow icon indicating copy to clipboard operation
anyhow copied to clipboard

Reconsider stracktrace configurability with rust 2024 set_var changes.

Open rukai opened this issue 1 year ago • 1 comments

I know there has already been a lot of discussion on this, so my apologies for bringing it up again, but rust 2024 will change the original context this decision may have been made in.

Previously I raised https://github.com/dtolnay/anyhow/issues/342 but then I found a workaround to disable anyhow backtrace capturing via:

if std::env::var("RUST_LIB_BACKTRACE").is_err() {
  std::env::set_var("RUST_LIB_BACKTRACE", "0");
}

This resolved my issue and the issue was closed.

However, with rust 2024, set_var will be marked unsafe. Many high level codebases have a blanket ban on unsafe, so even if set_var can be soundly called at the start of the application before any threads are created, there is no way to create a sound wrapper API for that as it could still be called after that point. So this approach is not usable in codebases with a blanket ban on unsafe.

Does this alter the original assumptions around the decision to "not expose a way for the application to configure whether stacktraces are captured"? If this changes nothing go ahead and close the issue.

rukai avatar Dec 30 '24 04:12 rukai

See rust-lang/rust#93346 for the proposals to control this via the standard library without needing std::env::set_var.

mattheww avatar Jan 19 '25 12:01 mattheww