rerun icon indicating copy to clipboard operation
rerun copied to clipboard

`anyhow::Error::to_string` doesn't print the full context

Open emilk opened this issue 11 months ago • 2 comments

This has bitten us many times. That's why we have re_error::format.

  • anyhow has no intention of changing this behavior: https://discord.com/channels/1062300748202921994/1373859622443548803/1373859622443548803
  • eyre has the same problem: https://github.com/eyre-rs/eyre/issues/234

emilk avatar Jan 14 '25 12:01 emilk

According to https://github.com/dtolnay/anyhow/issues/85, using format!("{err:#}") instead of err.to_string() prints the whole context.

let err = anyhow::format_err!("root_cause")
    .context("inner_context")
    .context("outer_context");

assert_eq!(
    format!("{:#}", err),
    "outer_context: inner_context: root_cause"
);

wyfo avatar Jun 04 '25 08:06 wyfo

Another place where disallowed trait methods would be super useful:

  • https://github.com/rust-lang/rust-clippy/issues/15765

Is there an open source bounty program for such things?

grtlr avatar Nov 11 '25 07:11 grtlr