diff --git a/rama-cli/src/error.rs b/rama-cli/src/error.rs index 4e7e066f..349a3711 100644 --- a/rama-cli/src/error.rs +++ b/rama-cli/src/error.rs @@ -38,6 +38,10 @@ impl std::fmt::Display for ErrorWithExitCode { impl std::error::Error for ErrorWithExitCode { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - self.error.source() + if let Some(err) = self.error.source() { + return Some(err); + } + let err = self.error.as_ref(); + Some(err as &(dyn std::error::Error + 'static)) } } diff --git a/rama-error/src/ext/backtrace.rs b/rama-error/src/ext/backtrace.rs index 8561a4ad..2336ef9a 100644 --- a/rama-error/src/ext/backtrace.rs +++ b/rama-error/src/ext/backtrace.rs @@ -43,6 +43,10 @@ impl Debug for BacktraceError { impl Error for BacktraceError { fn source(&self) -> Option<&(dyn Error + 'static)> { - self.inner.source() + if let Some(err) = self.inner.source() { + return Some(err); + } + let err = &self.inner; + Some(err as &(dyn std::error::Error + 'static)) } } diff --git a/rama-error/src/ext/context.rs b/rama-error/src/ext/context.rs index e8ab8eb0..ea29f4b9 100644 --- a/rama-error/src/ext/context.rs +++ b/rama-error/src/ext/context.rs @@ -34,7 +34,11 @@ where E: std::error::Error + 'static, { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - self.error.source() + if let Some(err) = self.error.source() { + return Some(err); + } + let err = &self.error; + Some(err as &(dyn std::error::Error + 'static)) } } diff --git a/rama-error/src/ext/mod.rs b/rama-error/src/ext/mod.rs index 88e63ed1..b7c60505 100644 --- a/rama-error/src/ext/mod.rs +++ b/rama-error/src/ext/mod.rs @@ -243,7 +243,11 @@ mod tests { impl std::error::Error for WrapperError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - Some(self.0.as_ref()) + if let Some(err) = self.0.source() { + return Some(err); + } + let err = self.0.as_ref(); + Some(err as &(dyn std::error::Error + 'static)) } } diff --git a/rama-error/src/ext/wrapper.rs b/rama-error/src/ext/wrapper.rs index 93f24452..60a26e4d 100644 --- a/rama-error/src/ext/wrapper.rs +++ b/rama-error/src/ext/wrapper.rs @@ -83,7 +83,11 @@ impl Display for OpaqueError { impl std::error::Error for OpaqueError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - self.0.source() + if let Some(err) = self.0.source() { + return Some(err); + } + let err = self.0.as_ref(); + Some(err as &(dyn std::error::Error + 'static)) } }