anyhow icon indicating copy to clipboard operation
anyhow copied to clipboard

Default {} is confusing, while {:#} is much better

Open ndmitchell opened this issue 4 years ago • 3 comments

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.

ndmitchell avatar Sep 04 '20 12:09 ndmitchell

Related issue: https://github.com/dtolnay/thiserror/issues/98

But I like this proposal to fix anyhow instead.

link2xt avatar Sep 30 '20 13:09 link2xt

What about a feature flag that makes {} behave the same as {:#}? Would this be possible?

Hocuri avatar Mar 03 '21 11:03 Hocuri

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.

link2xt avatar Mar 03 '21 11:03 link2xt