anyhow::Error to Box<dyn Error> isn't compatible with other libraries
Author: rkuklikCreated Mar 13, 2024Updated Jun 20, 2025
Hello,
I have to use multiple internal crates which mix and match anyhow and eyre. When trying to convert between the two, I have convert anyhow::Error to Box<dyn Error>, which then complains that conversion requires dyn Error to be Sized (in order for Box to implement Error). This results in this ugly solution when using Result<Something, ThinError>:
result
// Both `anyhow::Error` and `eyre::Report` support conversion into `Box`
.map_err(Into::<Box<dyn Error + Send + Sync>>::into)
// However, I have to stuff it into `Arc` which implements `Error` for `?Sized`
.map_err(Into::<Arc<dyn Error + Send + Sync>>::into)?Is there a better solution to this? If not, would it be possible to add conversion implementation from anyhow::Error into Arc or something equivalent? Unfortunately, I am unable to implement it, as it would require use of unsafe (with which I do not have enough experience) and because I am unfamiliar with techniques used in anyhow thinning.
Thank you very much in advance.
Source: dtolnay/anyhow