Skip to content

Commit 442d7da

Browse files
authored
cabi: return an empty string when no debug info (#776)
1 parent 1ae2353 commit 442d7da

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

minijinja-cabi/src/error.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,20 @@ pub unsafe extern "C" fn mj_err_get_debug_info() -> *mut c_char {
6060
.and_then(|x| {
6161
let mut info = String::new();
6262
if x.name().is_some() {
63-
writeln!(info, "{}", x.display_debug_info()).unwrap();
63+
let err_info = x.display_debug_info().to_string();
64+
if !err_info.is_empty() {
65+
writeln!(info, "{err_info}").unwrap();
66+
}
6467
}
6568
let mut source_opt = x.source();
6669
while let Some(source) = source_opt {
6770
writeln!(info, "\ncaused by: {source}").unwrap();
6871
if let Some(source) = source.downcast_ref::<Error>() {
6972
if source.name().is_some() {
70-
writeln!(info, "{}", source.display_debug_info()).unwrap();
73+
let src_info = x.display_debug_info().to_string();
74+
if !src_info.is_empty() {
75+
writeln!(info, "{src_info}").unwrap();
76+
}
7177
}
7278
}
7379
source_opt = source.source();

0 commit comments

Comments
 (0)