Skip to content

Commit 46a740a

Browse files
committed
Fix panic message being printed twice (godot_error! + eprintln!)
1 parent a0dede3 commit 46a740a

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

godot-core/src/meta/error/call_error.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,11 @@ impl CallError {
301301

302302
#[doc(hidden)]
303303
pub fn failed_by_user_panic(call_ctx: &CallContext, reason: String) -> Self {
304-
Self::new(call_ctx, reason, None)
304+
// This can cause the panic message to be printed twice in some scenarios (e.g. bind_mut() borrow failure).
305+
// But in other cases (e.g. itest `dynamic_call_with_panic`), it is only printed once.
306+
// Would need some work to have a consistent experience.
307+
308+
Self::new(call_ctx, format!("function panicked: {reason}"), None)
305309
}
306310

307311
fn new(

godot-core/src/private.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,11 +296,14 @@ where
296296

297297
let message = format_panic_message(panic_info);
298298
if godot_print() {
299+
// Also prints to stdout/stderr -- do not print twice.
299300
godot_error!("{message}");
301+
} else {
302+
eprintln!("{message}");
300303
}
301304

302305
let backtrace = format_backtrace!("panic backtrace");
303-
eprintln!("{message}{backtrace}");
306+
eprintln!("{backtrace}");
304307
let _ignored_result = std::io::stderr().flush();
305308
}));
306309
}

itest/rust/src/object_tests/dynamic_call_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ fn dynamic_call_with_panic() {
163163

164164
let expected_error_message = "godot-rust function call failed: Object::call(&\"do_panic\")\
165165
\n Source: ObjPayload::do_panic()\
166-
\n Reason: do_panic exploded"
166+
\n Reason: function panicked: do_panic exploded"
167167
.to_string();
168168

169169
assert_eq!(call_error.to_string(), expected_error_message);

0 commit comments

Comments
 (0)