From cc502379c1691bd8410b655275b7da4ef05d33a7 Mon Sep 17 00:00:00 2001 From: kyren Date: Tue, 26 Sep 2017 11:36:50 -0400 Subject: [PATCH] Print CallbackError in a better way CallbackError now, instead of displaying the cause description, instead prints "callback error: ". Since the cause is already in the cause chain of the error, this avoids repeatedly printing the cause of callback errors along the chain, and also actually prints the callback when using Display on each error in the chain. --- src/error.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/error.rs b/src/error.rs index 147f36c..7206df3 100644 --- a/src/error.rs +++ b/src/error.rs @@ -129,7 +129,9 @@ impl fmt::Display for Error { Error::UserDataTypeMismatch => write!(fmt, "userdata is not expected type"), Error::UserDataBorrowError => write!(fmt, "userdata already mutably borrowed"), Error::UserDataBorrowMutError => write!(fmt, "userdata already borrowed"), - Error::CallbackError { ref cause, .. } => write!(fmt, "{}", cause), + Error::CallbackError { ref traceback, .. } => { + write!(fmt, "callback error: {}", traceback) + } Error::ExternalError(ref err) => err.fmt(fmt), } } @@ -146,7 +148,7 @@ impl StdError for Error { Error::UserDataTypeMismatch => "userdata type mismatch", Error::UserDataBorrowError => "userdata already mutably borrowed", Error::UserDataBorrowMutError => "userdata already borrowed", - Error::CallbackError { ref cause, .. } => cause.description(), + Error::CallbackError { .. } => "callback error", Error::ExternalError(ref err) => err.description(), } }