anyhow
anyhow copied to clipboard
Default {} is confusing, while {:#} is much better
We've been using anyhow extensively, and it's worked out great. There's just one super confusing thing. I would expect:
println!("{}", anyhow!("My error message").context("on a file"))
To print at least My error message
, and ideally on a file
. But it just prints on a file
. I know {:#}
is available, but I've yet to find a case where we didn't want {:#}
and the usage of {}
is pretty pervasive - we've had it when printing messages nested, as format strings to thiserror
etc. It is the bug we seem to make every single time. I appreciate compatibility constraints might be hard, but switching the two (or even making them both the same) would be easier to use.
Related issue: https://github.com/dtolnay/thiserror/issues/98
But I like this proposal to fix anyhow instead.
What about a feature flag that makes {}
behave the same as {:#}
? Would this be possible?
Features are enabled when at least one dependency enables it, so they should not be used for "options". Otherwise pulling in a dependency which uses this "feature" will enable it for you and break your code and code of other dependencies which do not expect it.