Skip to content

Commit 6f5241d

Browse files
committed
Also display panics in other contexts inside Godot editor
1 parent 327c706 commit 6f5241d

File tree

4 files changed

+10
-6
lines changed

4 files changed

+10
-6
lines changed

gdnative-core/src/export/method.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -876,11 +876,12 @@ unsafe extern "C" fn method_wrapper<C: NativeClass, F: Method<C>>(
876876
});
877877

878878
result
879-
.unwrap_or_else(|_| {
879+
.unwrap_or_else(|e| {
880880
crate::log::error(
881881
F::site().unwrap_or_default(),
882882
"gdnative-core: method panicked (check stderr for output)",
883883
);
884+
crate::private::print_panic_error(e);
884885
Variant::nil()
885886
})
886887
.leak()

gdnative-core/src/export/property/accessor.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,9 @@ where
252252
}
253253
});
254254

255-
result.unwrap_or_else(|_| {
255+
result.unwrap_or_else(|e| {
256256
godot_error!("gdnative-core: property setter panicked (check stderr for output)");
257+
crate::private::print_panic_error(e);
257258
})
258259
}
259260
set.set_func = Some(invoke::<SelfArg, C, F, T>);
@@ -324,8 +325,9 @@ where
324325
}
325326
});
326327

327-
result.unwrap_or_else(|_| {
328+
result.unwrap_or_else(|e| {
328329
godot_error!("gdnative-core: property getter panicked (check stderr for output)");
330+
crate::private::print_panic_error(e);
329331
Variant::nil().leak()
330332
})
331333
}

gdnative-core/src/init/init_handle.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,12 @@ impl InitHandle {
123123
})
124124
})) {
125125
Ok(val) => val,
126-
Err(_) => {
126+
Err(e) => {
127127
godot_error!(
128128
"gdnative-core: error constructing {}: constructor panicked",
129129
class_registry::class_name_or_default::<C>(),
130130
);
131+
crate::private::print_panic_error(e);
131132
return ptr::null_mut();
132133
}
133134
};

gdnative-core/src/private.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,11 +188,11 @@ pub fn report_panics(context: &str, callback: impl FnOnce() + UnwindSafe) {
188188

189189
if let Err(e) = __result {
190190
godot_error!("gdnative-core: {} callback panicked", context);
191-
print_error(e);
191+
print_panic_error(e);
192192
}
193193
}
194194

195-
fn print_error(err: Box<dyn std::any::Any + Send>) {
195+
pub(crate) fn print_panic_error(err: Box<dyn std::any::Any + Send>) {
196196
if let Some(s) = err.downcast_ref::<String>() {
197197
godot_error!("Panic message: {}", s);
198198
} else if let Some(s) = err.downcast_ref::<&'static str>() {

0 commit comments

Comments
 (0)