瀏覽代碼

Improve error messages for method calls expecting only 1 argument

Rémi Verschelde 2 月之前
父節點
當前提交
d1083c9722

+ 1 - 1
core/math/expression.cpp

@@ -823,7 +823,7 @@ Expression::ENode *Expression::_parse_expression() {
 				if (!Variant::is_utility_function_vararg(bifunc->func)) {
 					int expected_args = Variant::get_utility_function_argument_count(bifunc->func);
 					if (expected_args != bifunc->arguments.size()) {
-						_set_error("Builtin func '" + String(bifunc->func) + "' expects " + itos(expected_args) + " arguments.");
+						_set_error("Builtin func '" + String(bifunc->func) + "' expects " + itos(expected_args) + " argument(s).");
 					}
 				}
 

+ 2 - 2
core/variant/variant.cpp

@@ -3501,9 +3501,9 @@ String Variant::get_call_error_text(Object *p_base, const StringName &p_method,
 			err_text = "Cannot convert argument " + itos(errorarg + 1) + " from [missing argptr, type unknown] to " + Variant::get_type_name(Variant::Type(ce.expected));
 		}
 	} else if (ce.error == Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS) {
-		err_text = "Method expected " + itos(ce.expected) + " arguments, but called with " + itos(p_argcount);
+		err_text = "Method expected " + itos(ce.expected) + " argument(s), but called with " + itos(p_argcount);
 	} else if (ce.error == Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS) {
-		err_text = "Method expected " + itos(ce.expected) + " arguments, but called with " + itos(p_argcount);
+		err_text = "Method expected " + itos(ce.expected) + " argument(s), but called with " + itos(p_argcount);
 	} else if (ce.error == Callable::CallError::CALL_ERROR_INVALID_METHOD) {
 		err_text = "Method not found";
 	} else if (ce.error == Callable::CallError::CALL_ERROR_INSTANCE_IS_NULL) {

+ 1 - 1
modules/gdscript/gdscript_vm.cpp

@@ -177,7 +177,7 @@ String GDScriptFunction::_get_call_error(const String &p_where, const Variant **
 			return "Invalid type in " + p_where + ". Cannot convert argument " + itos(p_err.argument + 1) + " from " + Variant::get_type_name(p_argptrs[p_err.argument]->get_type()) + " to " + Variant::get_type_name(Variant::Type(p_err.expected)) + ".";
 		case Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS:
 		case Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS:
-			return "Invalid call to " + p_where + ". Expected " + itos(p_err.expected) + " arguments.";
+			return "Invalid call to " + p_where + ". Expected " + itos(p_err.expected) + " argument(s).";
 		case Callable::CallError::CALL_ERROR_INSTANCE_IS_NULL:
 			return "Attempt to call " + p_where + " on a null instance.";
 		case Callable::CallError::CALL_ERROR_METHOD_NOT_CONST:

+ 1 - 1
modules/mono/glue/GodotSharp/GodotSharp/Core/Callable.cs

@@ -180,7 +180,7 @@ namespace Godot
         ///     static void Trampoline(object delegateObj, NativeVariantPtrArgs args, out godot_variant ret)
         ///     {
         ///         if (args.Count != 1)
-        ///             throw new ArgumentException($"Callable expected {1} arguments but received {args.Count}.");
+        ///             throw new ArgumentException($"Callable expected {1} argument but received {args.Count}.");
         ///
         ///         TResult res = ((Func<int, string>)delegateObj)(
         ///             VariantConversionCallbacks.GetToManagedCallback<int>()(args[0])

+ 1 - 1
modules/mono/glue/GodotSharp/GodotSharp/Core/Callable.generics.cs

@@ -19,7 +19,7 @@ public readonly partial struct Callable
         {
             throw new ArgumentException(
                 "Invalid argument count for invoking callable." +
-                $" Expected {countExpected} arguments, received {countReceived}.",
+                $" Expected {countExpected} argument(s), received {countReceived}.",
                 paramName);
         }
     }

+ 1 - 1
modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/ExceptionUtils.cs

@@ -211,7 +211,7 @@ namespace Godot.NativeInterop
                 }
                 case godot_variant_call_error_error.GODOT_CALL_ERROR_CALL_ERROR_TOO_MANY_ARGUMENTS:
                 case godot_variant_call_error_error.GODOT_CALL_ERROR_CALL_ERROR_TOO_FEW_ARGUMENTS:
-                    return $"Invalid call to {where}. Expected {error.Expected} arguments.";
+                    return $"Invalid call to {where}. Expected {error.Expected} argument(s).";
                 case godot_variant_call_error_error.GODOT_CALL_ERROR_CALL_ERROR_INVALID_METHOD:
                     return $"Invalid call. Nonexistent {where}.";
                 case godot_variant_call_error_error.GODOT_CALL_ERROR_CALL_ERROR_INSTANCE_IS_NULL:

+ 1 - 1
servers/rendering/shader_language.cpp

@@ -3578,7 +3578,7 @@ bool ShaderLanguage::_validate_function_call(BlockNode *p_block, const FunctionI
 				// Stage-based function.
 				const StageFunctionInfo &sf = E.value.stage_functions[name];
 				if (argcount != sf.arguments.size()) {
-					_set_error(vformat(RTR("Invalid number of arguments when calling stage function '%s', which expects %d arguments."), String(name), sf.arguments.size()));
+					_set_error(vformat(RTR("Invalid number of arguments when calling stage function '%s', which expects %d argument(s)."), String(name), sf.arguments.size()));
 					return false;
 				}
 				// Validate arguments.