alexcrichton opened issue #12690:
Discovered in #12689, this test currently fails:
#[test] #[cfg(feature = "anyhow")] fn anyhow_source_loses_downcast() -> Result<()> { let e: anyhow::Error = TestError(1).into(); assert!(e.downcast_ref::<TestError>().is_some()); let e: Error = Error::from_anyhow(e); assert!(e.downcast_ref::<TestError>().is_some()); Ok(()) }Specifically the
is,downcast,downcast_ref, anddowncast_mutmethods do not work onwasmtime::Errorwhen the original source of the error is ananyhow::Error. This is due to the way the implementation is organized right now where the holder ofanyhow::Errorreceives aTypeId, not a generic type parameter, menaing that we can't plumb this intoanyhow's methods.The fix for this is probably going to look like this where the existing methods, if they all fail, have a fall-through case which explicitly checks for
anyhow::Errorin the top-level methods withEtype parameters. If the underlying error isanyhow::Errorthen we'd also delegate toanyhow's methods with theEtype parameter.This is all in lieu of raw/
unsafeaccessors being added toanyhow, which is probably something we don't want to pursue just yet. I'll also know that convertinganyhow::Errortowasmtime::Errorand then back toanyhow::Errorwill work correctly after https://github.com/bytecodealliance/wasmtime/pull/12689 insofar as downcasts of the finalanyhow::Errorwill work as expected. That lessens the severity of this issue for now I think since embedders that areanyhowfocused can work around this issue with that sort of conversion.
alexcrichton added the bug label to Issue #12690.
fitzgen closed issue #12690:
Discovered in #12689, this test currently fails:
#[test] #[cfg(feature = "anyhow")] fn anyhow_source_loses_downcast() -> Result<()> { let e: anyhow::Error = TestError(1).into(); assert!(e.downcast_ref::<TestError>().is_some()); let e: Error = Error::from_anyhow(e); assert!(e.downcast_ref::<TestError>().is_some()); Ok(()) }Specifically the
is,downcast,downcast_ref, anddowncast_mutmethods do not work onwasmtime::Errorwhen the original source of the error is ananyhow::Error. This is due to the way the implementation is organized right now where the holder ofanyhow::Errorreceives aTypeId, not a generic type parameter, menaing that we can't plumb this intoanyhow's methods.The fix for this is probably going to look like this where the existing methods, if they all fail, have a fall-through case which explicitly checks for
anyhow::Errorin the top-level methods withEtype parameters. If the underlying error isanyhow::Errorthen we'd also delegate toanyhow's methods with theEtype parameter.This is all in lieu of raw/
unsafeaccessors being added toanyhow, which is probably something we don't want to pursue just yet. I'll also know that convertinganyhow::Errortowasmtime::Errorand then back toanyhow::Errorwill work correctly after https://github.com/bytecodealliance/wasmtime/pull/12689 insofar as downcasts of the finalanyhow::Errorwill work as expected. That lessens the severity of this issue for now I think since embedders that areanyhowfocused can work around this issue with that sort of conversion.
Last updated: Mar 23 2026 at 16:19 UTC