Skip to content

Commit a61ac5a

Browse files
committed
Use Display instead of Debug for failed method calls; elaborate error description
1 parent 5c80946 commit a61ac5a

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

gdnative-core/src/nativescript/macros.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ macro_rules! godot_wrap_method_inner {
204204
<$retty as $crate::core_types::OwnedToVariant>::owned_to_variant(ret)
205205
})
206206
.unwrap_or_else(|err| {
207-
$crate::godot_error!("gdnative-core: method call failed with error: {:?}", err);
207+
$crate::godot_error!("gdnative-core: method call failed with error: {}", err);
208208
$crate::godot_error!("gdnative-core: check module level documentation on gdnative::user_data for more information");
209209
$crate::core_types::Variant::new()
210210
});

gdnative-core/src/nativescript/user_data.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,13 @@ pub type DefaultUserData<T> = LocalCellData<T>;
153153
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
154154
pub enum Infallible {}
155155

156+
impl std::fmt::Display for Infallible {
157+
#[inline]
158+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
159+
write!(f, "Operation that can't fail just failed")
160+
}
161+
}
162+
156163
/// Policies to deal with potential deadlocks
157164
///
158165
/// As Godot allows mutable pointer aliasing, doing certain things in exported method bodies may
@@ -526,7 +533,11 @@ mod local_cell {
526533
"Accessing from the wrong thread, expected {:?} found {:?}",
527534
original, current
528535
),
529-
LocalCellError::BorrowFailed => write!(f, "Borrow Failed"),
536+
LocalCellError::BorrowFailed => write!(
537+
f,
538+
"Borrow failed; a &mut reference was requested, but one already exists. Cause is likely a re-entrant call \
539+
(e.g. a GDNative Rust method calls to GDScript, which again calls a Rust method on the same object)."
540+
),
530541
}
531542
}
532543
}

0 commit comments

Comments
 (0)