Skip to content

Commit 5bb272e

Browse files
committed
Update conversion errors to new ElementType
Leverages the new ElementType information for validation, and makes conversion error messages more uniform.
1 parent 66466df commit 5bb272e

File tree

2 files changed

+15
-28
lines changed

2 files changed

+15
-28
lines changed

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

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,10 @@ pub(crate) enum FromGodotError {
187187

188188
/// Special case of `BadArrayType` where a custom int type such as `i8` cannot hold a dynamic `i64` value.
189189
#[cfg(debug_assertions)]
190-
BadArrayTypeInt { expected: ArrayTypeInfo, value: i64 },
190+
BadArrayTypeInt {
191+
expected_int_type: &'static str,
192+
value: i64,
193+
},
191194

192195
/// InvalidEnum is also used by bitfields.
193196
InvalidEnum,
@@ -219,39 +222,23 @@ impl fmt::Display for FromGodotError {
219222
match self {
220223
Self::BadArrayType { expected, actual } => {
221224
if expected.variant_type() != actual.variant_type() {
222-
return if expected.is_typed() {
223-
write!(
224-
f,
225-
"expected array of type {:?}, got array of type {:?}",
226-
expected.variant_type(),
227-
actual.variant_type()
228-
)
229-
} else {
230-
write!(
231-
f,
232-
"expected untyped array, got array of type {:?}",
233-
actual.variant_type()
234-
)
235-
};
225+
// Includes either of two sides being Untyped (VARIANT).
226+
return write!(f, "expected array of type {expected:?}, got {actual:?}");
236227
}
237228

238-
let exp_class = expected.class_name().expect("lhs class name present");
239-
let act_class = actual.class_name().expect("rhs class name present");
240-
assert_ne!(
241-
exp_class, act_class,
242-
"BadArrayType with expected == got, this is a gdext bug"
243-
);
229+
let exp_class = format!("{expected:?}");
230+
let act_class = format!("{actual:?}");
244231

245-
write!(
246-
f,
247-
"expected array of class {exp_class}, got array of class {act_class}"
248-
)
232+
write!(f, "expected array of type {exp_class}, got {act_class}")
249233
}
250234
#[cfg(debug_assertions)]
251-
Self::BadArrayTypeInt { expected, value } => {
235+
Self::BadArrayTypeInt {
236+
expected_int_type,
237+
value,
238+
} => {
252239
write!(
253240
f,
254-
"integer value {value} does not fit into Array of type {expected:?}"
241+
"integer value {value} does not fit into Array<{expected_int_type}>"
255242
)
256243
}
257244
Self::InvalidEnum => write!(f, "invalid engine enum value"),

godot-core/src/meta/godot_convert/impls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ macro_rules! impl_godot_scalar {
199199
// For integer types, we can validate the conversion.
200200
impl ArrayElement for $T {
201201
fn debug_validate_elements(array: &Array<Self>) -> Result<(), ConvertError> {
202-
array.debug_validate_elements()
202+
array.debug_validate_int_elements()
203203
}
204204
}
205205

0 commit comments

Comments
 (0)