cameleon icon indicating copy to clipboard operation
cameleon copied to clipboard

Stop using `anyhow::Error`?

Open strohel opened this issue 10 months ago • 2 comments

I see that cameleon uses anyhow::Error, but very lightly: https://github.com/search?q=repo%3Acameleon-rs%2Fcameleon%20anyhow&type=code (only for 2 Io error variants).

Anyhow specifically isn't designed for library errors, so it would be best to replace these with something different, perhaps custom thiserror-derived errors (which has a benefit of not ending up in the crate signature).

A nice side-effect would be removing the dependency (for people that don't use anyhow in their apps).

Or @Y-Nak do you recall having a specific reason to use anyhow? CC @bschwind @mbernat.

strohel avatar Apr 03 '24 13:04 strohel

  1. I believe the guideline is to use bespoke errors for libraries as much as possible; thiserror helps with this.
  2. The other option is to use something like Box<dyn std::error::Error>. Not as nice but at least it's using a stable type.
  3. The least appealing option is to use a library error (such as anyhow's) because these are not stable, so a semver hazard. See eyre's rationale, it should apply verbatim to anyhow as well.

mbernat avatar Apr 04 '24 02:04 mbernat

I agree to remove anyhow and use thiserror instead. I don't remember why I decided to use anyhow here. I probably intended to use it as a stopgap before elaborating error kinds, then forgot to fix it 😅

Y-Nak avatar Apr 05 '24 09:04 Y-Nak