From b30f5c594bd1fdabcaac9ba4a3feddb26d82752b Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 4 Sep 2022 14:09:59 -0700 Subject: [PATCH] Include outer backtrace when called as source.provide --- src/error.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/error.rs b/src/error.rs index 4256c77..d707297 100644 --- a/src/error.rs +++ b/src/error.rs @@ -522,6 +522,17 @@ impl Error { Some(addr.cast::().deref_mut()) } } + + // Called by thiserror when you have `#[source] anyhow::Error`. This provide + // implementation includes the anyhow::Error's Backtrace if any, unlike + // deref'ing to dyn Error where the provide implementation would include + // only the original error's Backtrace from before it got wrapped into an + // anyhow::Error. + #[cfg(backtrace)] + #[doc(hidden)] + pub fn provide<'a>(&'a self, demand: &mut Demand<'a>) { + unsafe { ErrorImpl::provide(self.inner.by_ref(), demand) } + } } #[cfg(feature = "std")]