Skip to content

Commit

Permalink
fix stack overflow in Error's Display impl
Browse files Browse the repository at this point in the history
  • Loading branch information
canndrew committed Feb 23, 2019
1 parent 82eef13 commit ed70613
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion lib/runtime-core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,24 @@ impl From<ResolveError> 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),
}
}
}

Expand Down

0 comments on commit ed70613

Please sign in to comment.