From ed706133c463edfcf61d5b981752ed00e7d92ec4 Mon Sep 17 00:00:00 2001 From: Andrew Cann Date: Sat, 23 Feb 2019 17:00:03 +0800 Subject: [PATCH 1/2] fix stack overflow in Error's Display impl --- lib/runtime-core/src/error.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/runtime-core/src/error.rs b/lib/runtime-core/src/error.rs index 1f9f60c61..fea5c1e2e 100644 --- a/lib/runtime-core/src/error.rs +++ b/lib/runtime-core/src/error.rs @@ -365,7 +365,24 @@ impl From for CallError { impl std::fmt::Display for Error { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - write!(f, "{}", self) + match self { + Error::CompileError(err) => write!(f, "compile error: {}", err), + Error::LinkError(errs) => { + if errs.len() == 1 { + write!(f, "link error: {}", errs[0]) + } else { + write!(f, "{} link errors:", errs.len())?; + for (i, err) in errs.iter().enumerate() { + write!(f, " ({} of {}) {}", i + 1, errs.len(), err)?; + } + Ok(()) + } + }, + Error::RuntimeError(err) => write!(f, "runtime error: {}", err), + Error::ResolveError(err) => write!(f, "resolve error: {}", err), + Error::CallError(err) => write!(f, "call error: {}", err), + Error::CreationError(err) => write!(f, "creation error: {}", err), + } } } From f9c0e0c07869306b5fbb027210ae062745e908c8 Mon Sep 17 00:00:00 2001 From: Syrus Date: Mon, 25 Feb 2019 12:25:28 -0800 Subject: [PATCH 2/2] Fix formatting --- lib/runtime-core/src/error.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/runtime-core/src/error.rs b/lib/runtime-core/src/error.rs index fea5c1e2e..abc69cc5e 100644 --- a/lib/runtime-core/src/error.rs +++ b/lib/runtime-core/src/error.rs @@ -377,7 +377,7 @@ impl std::fmt::Display for Error { } Ok(()) } - }, + } Error::RuntimeError(err) => write!(f, "runtime error: {}", err), Error::ResolveError(err) => write!(f, "resolve error: {}", err), Error::CallError(err) => write!(f, "call error: {}", err),