From 5bdd519d67527b1052fa15495eae8c145c4af1e3 Mon Sep 17 00:00:00 2001 From: Balloonpopper Date: Tue, 22 Feb 2022 18:05:03 +1100 Subject: [PATCH] feat: more useful error messages --- .../types/esc_command_argument_descriptor.gd | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/addons/escoria-core/game/core-scripts/esc/types/esc_command_argument_descriptor.gd b/addons/escoria-core/game/core-scripts/esc/types/esc_command_argument_descriptor.gd index a9fd61bc..5c8151c5 100644 --- a/addons/escoria-core/game/core-scripts/esc/types/esc_command_argument_descriptor.gd +++ b/addons/escoria-core/game/core-scripts/esc/types/esc_command_argument_descriptor.gd @@ -2,6 +2,15 @@ extends Object class_name ESCCommandArgumentDescriptor +# As the get_type command was deprecated with Godot 2.x w we need a way to determine +# variable types. Ideally these wouldn't be hardcoded but there's no GDScript 3.x command to +# turn a type back to its name. +const GODOT_TYPE_LIST = ["nil", "bool", "int", "real", "string", \ + "vector2", "rect2", "vector3", "matrix32", "plane", "quat", \ + "aabb", "matrix3", "transform", "color", "image", "node_path", \ + "rid", "object", "input_event", "dictionary", "array", \ + "raw_array", "int_array", "real_array", "string_array", \ + "vector2_array", "vector3_array", "color_array", "max"] # Number of arguments the command expects var min_args: int = 0 @@ -80,20 +89,22 @@ func validate(command: String, arguments: Array) -> bool: correct = self._is_type(arguments[index], type) if not correct: + var allowed_types = "[ " + for type in self.types[types_index]: + allowed_types += GODOT_TYPE_LIST[type] + " or " + allowed_types = allowed_types.substr(0, allowed_types.length() - 3) + "]" escoria.logger.report_errors( - "Argument type did not match descriptor for command %s" % + "Argument type did not match descriptor for command \"%s\"" % command, [ - "Argument %d is of type %d. Expected %s" % [ + "Argument %d (\"%s\") is of type %s. Expected %s" % [ index, - typeof(arguments[index]), - PoolStringArray( - self.types[types_index] - ).join(",") + arguments[index], + GODOT_TYPE_LIST[typeof(arguments[index])], + allowed_types ] ] ) - return true