From 892069edd64c73e06c23ea24b77a4457124a38fb Mon Sep 17 00:00:00 2001 From: kyren Date: Thu, 26 Oct 2017 16:49:16 -0400 Subject: [PATCH] Correctly wrap external errors so that Debug trait and Error::cause are correct --- src/error.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/error.rs b/src/error.rs index 7206df3..04e909a 100644 --- a/src/error.rs +++ b/src/error.rs @@ -177,12 +177,17 @@ where E: Into>, { fn to_lua_err(self) -> Error { - #[derive(Debug)] struct WrapError(Box); + impl fmt::Debug for WrapError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(&self.0, f) + } + } + impl fmt::Display for WrapError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - self.0.fmt(f) + fmt::Display::fmt(&self.0, f) } } @@ -190,6 +195,10 @@ where fn description(&self) -> &str { self.0.description() } + + fn cause(&self) -> Option<&StdError> { + self.0.cause() + } } Error::external(WrapError(self.into()))