Correctly wrap external errors so that Debug trait and Error::cause are correct

This commit is contained in:
kyren 2017-10-26 16:49:16 -04:00
parent 8592af1b16
commit 892069edd6
1 changed files with 11 additions and 2 deletions

View File

@ -177,12 +177,17 @@ where
E: Into<Box<StdError + Send + Sync>>,
{
fn to_lua_err(self) -> Error {
#[derive(Debug)]
struct WrapError(Box<StdError + Send + Sync>);
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()))