anyhow::Error to Box<dyn Error> isn't compatible with other libraries
Opened this issue · 2 comments
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.
Same question, why doesn't anyhow implement std::error:Error
?
Because it implements From<E> where E: Error
, which would clash with blanket implementation (you can convert any type into itself). It's the same reason for Box
complains about Sized
constraint to implement Error
.
I solved this by wrapping anyhow::Error
in newtype and implementing Error
for that.