mirror of
https://github.com/godotengine/godot.git
synced 2024-11-22 04:06:14 +00:00
Merge pull request #93897 from akien-mga/vformat-better-error-message
Core: Improve `vformat` error reporting on `sprintf` failure
This commit is contained in:
commit
daba91d8c6
@ -235,7 +235,7 @@ void Array::assign(const Array &p_array) {
|
||||
for (int i = 0; i < size; i++) {
|
||||
const Variant &element = source[i];
|
||||
if (element.get_type() != Variant::NIL && (element.get_type() != Variant::OBJECT || !typed.validate_object(element, "assign"))) {
|
||||
ERR_FAIL_MSG(vformat(R"(Unable to convert array index %i from "%s" to "%s".)", i, Variant::get_type_name(element.get_type()), Variant::get_type_name(typed.type)));
|
||||
ERR_FAIL_MSG(vformat(R"(Unable to convert array index %d from "%s" to "%s".)", i, Variant::get_type_name(element.get_type()), Variant::get_type_name(typed.type)));
|
||||
}
|
||||
}
|
||||
_p->array = p_array._p->array;
|
||||
@ -258,11 +258,11 @@ void Array::assign(const Array &p_array) {
|
||||
continue;
|
||||
}
|
||||
if (!Variant::can_convert_strict(value->get_type(), typed.type)) {
|
||||
ERR_FAIL_MSG("Unable to convert array index " + itos(i) + " from '" + Variant::get_type_name(value->get_type()) + "' to '" + Variant::get_type_name(typed.type) + "'.");
|
||||
ERR_FAIL_MSG(vformat(R"(Unable to convert array index %d from "%s" to "%s".)", i, Variant::get_type_name(value->get_type()), Variant::get_type_name(typed.type)));
|
||||
}
|
||||
Callable::CallError ce;
|
||||
Variant::construct(typed.type, data[i], &value, 1, ce);
|
||||
ERR_FAIL_COND_MSG(ce.error, vformat(R"(Unable to convert array index %i from "%s" to "%s".)", i, Variant::get_type_name(value->get_type()), Variant::get_type_name(typed.type)));
|
||||
ERR_FAIL_COND_MSG(ce.error, vformat(R"(Unable to convert array index %d from "%s" to "%s".)", i, Variant::get_type_name(value->get_type()), Variant::get_type_name(typed.type)));
|
||||
}
|
||||
} else if (Variant::can_convert_strict(source_typed.type, typed.type)) {
|
||||
// from primitives to different convertible primitives
|
||||
@ -270,7 +270,7 @@ void Array::assign(const Array &p_array) {
|
||||
const Variant *value = source + i;
|
||||
Callable::CallError ce;
|
||||
Variant::construct(typed.type, data[i], &value, 1, ce);
|
||||
ERR_FAIL_COND_MSG(ce.error, vformat(R"(Unable to convert array index %i from "%s" to "%s".)", i, Variant::get_type_name(value->get_type()), Variant::get_type_name(typed.type)));
|
||||
ERR_FAIL_COND_MSG(ce.error, vformat(R"(Unable to convert array index %d from "%s" to "%s".)", i, Variant::get_type_name(value->get_type()), Variant::get_type_name(typed.type)));
|
||||
}
|
||||
} else {
|
||||
ERR_FAIL_MSG(vformat(R"(Cannot assign contents of "Array[%s]" to "Array[%s]".)", Variant::get_type_name(source_typed.type), Variant::get_type_name(typed.type)));
|
||||
|
@ -857,7 +857,7 @@ String vformat(const String &p_text, const VarArgs... p_args) {
|
||||
bool error = false;
|
||||
String fmt = p_text.sprintf(args_array, &error);
|
||||
|
||||
ERR_FAIL_COND_V_MSG(error, String(), fmt);
|
||||
ERR_FAIL_COND_V_MSG(error, String(), String("Formatting error in string \"") + p_text + "\": " + fmt + ".");
|
||||
|
||||
return fmt;
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
GDTEST_RUNTIME_ERROR
|
||||
>> ERROR
|
||||
>> Method/function failed.
|
||||
>> Unable to convert array index 0 from "Object" to "Object".
|
||||
not ok
|
||||
|
Loading…
Reference in New Issue
Block a user