Skip to content

Commit 1a3266f

Browse files
committed
Handle cpp demangling failing
1 parent a933fcf commit 1a3266f

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/symbolize/mod.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -218,13 +218,23 @@ cfg_if! {
218218
if #[cfg(feature = "cpp_demangle")] {
219219
impl<'a> fmt::Debug for SymbolName<'a> {
220220
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
221+
use std::fmt::Write;
222+
221223
if let Some(ref s) = self.demangled {
222-
s.fmt(f)
223-
} else if let Some(ref cpp) = self.cpp_demangled.0 {
224-
fmt::Display::fmt(cpp, f)
225-
} else {
226-
String::from_utf8_lossy(self.bytes).fmt(f)
224+
return s.fmt(f)
225+
}
226+
227+
// This may to print if the demangled symbol isn't actually
228+
// valid, so handle the error here gracefully by not propagating
229+
// it outwards.
230+
if let Some(ref cpp) = self.cpp_demangled.0 {
231+
let mut s = String::new();
232+
if write!(s, "{}", cpp).is_ok() {
233+
return s.fmt(f)
234+
}
227235
}
236+
237+
String::from_utf8_lossy(self.bytes).fmt(f)
228238
}
229239
}
230240
} else {

0 commit comments

Comments
 (0)