Parcourir la source

Properly expose all Error constants to scripting languages

(cherry picked from commit 1bf448dd8713dd0524966096ba198bdb077fe998)
Rémi Verschelde il y a 6 ans
Parent
commit
7a97fd99c7

+ 4 - 4
core/error_list.h

@@ -39,7 +39,7 @@
  */
 
 enum Error {
-	OK,
+	OK, // (0)
 	FAILED, ///< Generic fail error
 	ERR_UNAVAILABLE, ///< What is requested is unsupported/unavailable
 	ERR_UNCONFIGURED, ///< The object being used hasn't been properly set up yet
@@ -69,12 +69,12 @@ enum Error {
 	ERR_CONNECTION_ERROR,
 	ERR_CANT_ACQUIRE_RESOURCE,
 	ERR_CANT_FORK,
-	ERR_INVALID_DATA, ///< Data passed is invalid	(30)
+	ERR_INVALID_DATA, ///< Data passed is invalid (30)
 	ERR_INVALID_PARAMETER, ///< Parameter passed is invalid
 	ERR_ALREADY_EXISTS, ///< When adding, item already exists
-	ERR_DOES_NOT_EXIST, ///< When retrieving/erasing, it item does not exist
+	ERR_DOES_NOT_EXIST, ///< When retrieving/erasing, if item does not exist
 	ERR_DATABASE_CANT_READ, ///< database is full
-	ERR_DATABASE_CANT_WRITE, ///< database is full	(35)
+	ERR_DATABASE_CANT_WRITE, ///< database is full (35)
 	ERR_COMPILATION_FAILED,
 	ERR_METHOD_NOT_FOUND,
 	ERR_LINK_FAILED,

+ 30 - 22
core/global_constants.cpp

@@ -470,47 +470,55 @@ void register_global_constants() {
 
 	// error list
 
-	BIND_GLOBAL_ENUM_CONSTANT(OK);
-	BIND_GLOBAL_ENUM_CONSTANT(FAILED); ///< Generic fail error
-	BIND_GLOBAL_ENUM_CONSTANT(ERR_UNAVAILABLE); ///< What is requested is unsupported/unavailable
-	BIND_GLOBAL_ENUM_CONSTANT(ERR_UNCONFIGURED); ///< The object being used hasn't been properly set up yet
-	BIND_GLOBAL_ENUM_CONSTANT(ERR_UNAUTHORIZED); ///< Missing credentials for requested resource
-	BIND_GLOBAL_ENUM_CONSTANT(ERR_PARAMETER_RANGE_ERROR); ///< Parameter given out of range
-	BIND_GLOBAL_ENUM_CONSTANT(ERR_OUT_OF_MEMORY); ///< Out of memory
+	BIND_GLOBAL_ENUM_CONSTANT(OK); // (0)
+	BIND_GLOBAL_ENUM_CONSTANT(FAILED);
+	BIND_GLOBAL_ENUM_CONSTANT(ERR_UNAVAILABLE);
+	BIND_GLOBAL_ENUM_CONSTANT(ERR_UNCONFIGURED);
+	BIND_GLOBAL_ENUM_CONSTANT(ERR_UNAUTHORIZED);
+	BIND_GLOBAL_ENUM_CONSTANT(ERR_PARAMETER_RANGE_ERROR); // (5)
+	BIND_GLOBAL_ENUM_CONSTANT(ERR_OUT_OF_MEMORY);
 	BIND_GLOBAL_ENUM_CONSTANT(ERR_FILE_NOT_FOUND);
 	BIND_GLOBAL_ENUM_CONSTANT(ERR_FILE_BAD_DRIVE);
 	BIND_GLOBAL_ENUM_CONSTANT(ERR_FILE_BAD_PATH);
-	BIND_GLOBAL_ENUM_CONSTANT(ERR_FILE_NO_PERMISSION);
+	BIND_GLOBAL_ENUM_CONSTANT(ERR_FILE_NO_PERMISSION); // (10)
 	BIND_GLOBAL_ENUM_CONSTANT(ERR_FILE_ALREADY_IN_USE);
 	BIND_GLOBAL_ENUM_CONSTANT(ERR_FILE_CANT_OPEN);
 	BIND_GLOBAL_ENUM_CONSTANT(ERR_FILE_CANT_WRITE);
 	BIND_GLOBAL_ENUM_CONSTANT(ERR_FILE_CANT_READ);
-	BIND_GLOBAL_ENUM_CONSTANT(ERR_FILE_UNRECOGNIZED);
+	BIND_GLOBAL_ENUM_CONSTANT(ERR_FILE_UNRECOGNIZED); // (15)
 	BIND_GLOBAL_ENUM_CONSTANT(ERR_FILE_CORRUPT);
 	BIND_GLOBAL_ENUM_CONSTANT(ERR_FILE_MISSING_DEPENDENCIES);
 	BIND_GLOBAL_ENUM_CONSTANT(ERR_FILE_EOF);
-	BIND_GLOBAL_ENUM_CONSTANT(ERR_CANT_OPEN); ///< Can't open a resource/socket/file
-	BIND_GLOBAL_ENUM_CONSTANT(ERR_CANT_CREATE);
-	BIND_GLOBAL_ENUM_CONSTANT(ERR_PARSE_ERROR);
+	BIND_GLOBAL_ENUM_CONSTANT(ERR_CANT_OPEN);
+	BIND_GLOBAL_ENUM_CONSTANT(ERR_CANT_CREATE); // (20)
 	BIND_GLOBAL_ENUM_CONSTANT(ERR_QUERY_FAILED);
 	BIND_GLOBAL_ENUM_CONSTANT(ERR_ALREADY_IN_USE);
-	BIND_GLOBAL_ENUM_CONSTANT(ERR_LOCKED); ///< resource is locked
+	BIND_GLOBAL_ENUM_CONSTANT(ERR_LOCKED);
 	BIND_GLOBAL_ENUM_CONSTANT(ERR_TIMEOUT);
+	BIND_GLOBAL_ENUM_CONSTANT(ERR_CANT_CONNECT); // (25)
+	BIND_GLOBAL_ENUM_CONSTANT(ERR_CANT_RESOLVE);
+	BIND_GLOBAL_ENUM_CONSTANT(ERR_CONNECTION_ERROR);
 	BIND_GLOBAL_ENUM_CONSTANT(ERR_CANT_ACQUIRE_RESOURCE);
-	BIND_GLOBAL_ENUM_CONSTANT(ERR_INVALID_DATA); ///< Data passed is invalid
-	BIND_GLOBAL_ENUM_CONSTANT(ERR_INVALID_PARAMETER); ///< Parameter passed is invalid
-	BIND_GLOBAL_ENUM_CONSTANT(ERR_ALREADY_EXISTS); ///< When adding ), item already exists
-	BIND_GLOBAL_ENUM_CONSTANT(ERR_DOES_NOT_EXIST); ///< When retrieving/erasing ), it item does not exist
-	BIND_GLOBAL_ENUM_CONSTANT(ERR_DATABASE_CANT_READ); ///< database is full
-	BIND_GLOBAL_ENUM_CONSTANT(ERR_DATABASE_CANT_WRITE); ///< database is full
+	BIND_GLOBAL_ENUM_CONSTANT(ERR_CANT_FORK);
+	BIND_GLOBAL_ENUM_CONSTANT(ERR_INVALID_DATA); // (30)
+	BIND_GLOBAL_ENUM_CONSTANT(ERR_INVALID_PARAMETER);
+	BIND_GLOBAL_ENUM_CONSTANT(ERR_ALREADY_EXISTS);
+	BIND_GLOBAL_ENUM_CONSTANT(ERR_DOES_NOT_EXIST);
+	BIND_GLOBAL_ENUM_CONSTANT(ERR_DATABASE_CANT_READ);
+	BIND_GLOBAL_ENUM_CONSTANT(ERR_DATABASE_CANT_WRITE); // (35)
 	BIND_GLOBAL_ENUM_CONSTANT(ERR_COMPILATION_FAILED);
 	BIND_GLOBAL_ENUM_CONSTANT(ERR_METHOD_NOT_FOUND);
 	BIND_GLOBAL_ENUM_CONSTANT(ERR_LINK_FAILED);
 	BIND_GLOBAL_ENUM_CONSTANT(ERR_SCRIPT_FAILED);
-	BIND_GLOBAL_ENUM_CONSTANT(ERR_CYCLIC_LINK);
+	BIND_GLOBAL_ENUM_CONSTANT(ERR_CYCLIC_LINK); // (40)
+	BIND_GLOBAL_ENUM_CONSTANT(ERR_INVALID_DECLARATION);
+	BIND_GLOBAL_ENUM_CONSTANT(ERR_DUPLICATE_SYMBOL);
+	BIND_GLOBAL_ENUM_CONSTANT(ERR_PARSE_ERROR);
 	BIND_GLOBAL_ENUM_CONSTANT(ERR_BUSY);
-	BIND_GLOBAL_ENUM_CONSTANT(ERR_HELP); ///< user requested help!!
-	BIND_GLOBAL_ENUM_CONSTANT(ERR_BUG); ///< a bug in the software certainly happened ), due to a double check failing or unexpected behavior.
+	BIND_GLOBAL_ENUM_CONSTANT(ERR_SKIP); // (45)
+	BIND_GLOBAL_ENUM_CONSTANT(ERR_HELP);
+	BIND_GLOBAL_ENUM_CONSTANT(ERR_BUG);
+	BIND_GLOBAL_ENUM_CONSTANT(ERR_PRINTER_ON_FIRE);
 
 	BIND_GLOBAL_ENUM_CONSTANT(PROPERTY_HINT_NONE);
 	BIND_GLOBAL_ENUM_CONSTANT(PROPERTY_HINT_RANGE);

+ 75 - 42
doc/classes/@GlobalScope.xml

@@ -1099,127 +1099,160 @@
 		<constant name="MIDI_MESSAGE_PITCH_BEND" value="14" enum="MidiMessageList">
 		</constant>
 		<constant name="OK" value="0" enum="Error">
-			Functions that return Error return OK when no error occurred. Most functions don't return errors and/or just print errors to STDOUT.
+			Methods that return [enum Error] return [constant OK] when no error occurred. Note that many functions don't return an error code but will print error messages to stdout.
+			Since [constant OK] has value 0, and all other failure codes are positive integers, it can also be used in boolean checks, e.g.:
+			[codeblock]
+			var err = method_that_returns_error()
+			if (err != OK):
+			    print("Failure!)
+			# Or, equivalent:
+			if (err):
+			    print("Still failing!)
+			[/codeblock]
 		</constant>
 		<constant name="FAILED" value="1" enum="Error">
 			Generic error.
 		</constant>
 		<constant name="ERR_UNAVAILABLE" value="2" enum="Error">
-			Unavailable error
+			Unavailable error.
 		</constant>
 		<constant name="ERR_UNCONFIGURED" value="3" enum="Error">
-			Unconfigured error
+			Unconfigured error.
 		</constant>
 		<constant name="ERR_UNAUTHORIZED" value="4" enum="Error">
-			Unauthorized error
+			Unauthorized error.
 		</constant>
 		<constant name="ERR_PARAMETER_RANGE_ERROR" value="5" enum="Error">
-			Parameter range error
+			Parameter range error.
 		</constant>
 		<constant name="ERR_OUT_OF_MEMORY" value="6" enum="Error">
-			Out of memory (OOM) error
+			Out of memory (OOM) error.
 		</constant>
 		<constant name="ERR_FILE_NOT_FOUND" value="7" enum="Error">
-			File: Not found error
+			File: Not found error.
 		</constant>
 		<constant name="ERR_FILE_BAD_DRIVE" value="8" enum="Error">
-			File: Bad drive error
+			File: Bad drive error.
 		</constant>
 		<constant name="ERR_FILE_BAD_PATH" value="9" enum="Error">
-			File: Bad path error
+			File: Bad path error.
 		</constant>
 		<constant name="ERR_FILE_NO_PERMISSION" value="10" enum="Error">
-			File: No permission error
+			File: No permission error.
 		</constant>
 		<constant name="ERR_FILE_ALREADY_IN_USE" value="11" enum="Error">
-			File: Already in use error
+			File: Already in use error.
 		</constant>
 		<constant name="ERR_FILE_CANT_OPEN" value="12" enum="Error">
-			File: Can't open error
+			File: Can't open error.
 		</constant>
 		<constant name="ERR_FILE_CANT_WRITE" value="13" enum="Error">
-			File: Can't write error
+			File: Can't write error.
 		</constant>
 		<constant name="ERR_FILE_CANT_READ" value="14" enum="Error">
-			File: Can't read error
+			File: Can't read error.
 		</constant>
 		<constant name="ERR_FILE_UNRECOGNIZED" value="15" enum="Error">
-			File: Unrecognized error
+			File: Unrecognized error.
 		</constant>
 		<constant name="ERR_FILE_CORRUPT" value="16" enum="Error">
-			File: Corrupt error
+			File: Corrupt error.
 		</constant>
 		<constant name="ERR_FILE_MISSING_DEPENDENCIES" value="17" enum="Error">
-			File: Missing dependencies error
+			File: Missing dependencies error.
 		</constant>
 		<constant name="ERR_FILE_EOF" value="18" enum="Error">
-			File: End of file (EOF) error
+			File: End of file (EOF) error.
 		</constant>
 		<constant name="ERR_CANT_OPEN" value="19" enum="Error">
-			Can't open error
+			Can't open error.
 		</constant>
 		<constant name="ERR_CANT_CREATE" value="20" enum="Error">
-			Can't create error
-		</constant>
-		<constant name="ERR_PARSE_ERROR" value="43" enum="Error">
-			Parse error
+			Can't create error.
 		</constant>
 		<constant name="ERR_QUERY_FAILED" value="21" enum="Error">
-			Query failed error
+			Query failed error.
 		</constant>
 		<constant name="ERR_ALREADY_IN_USE" value="22" enum="Error">
-			Already in use error
+			Already in use error.
 		</constant>
 		<constant name="ERR_LOCKED" value="23" enum="Error">
-			Locked error
+			Locked error.
 		</constant>
 		<constant name="ERR_TIMEOUT" value="24" enum="Error">
-			Timeout error
+			Timeout error.
+		</constant>
+		<constant name="ERR_CANT_CONNECT" value="25" enum="Error">
+			Can't connect error.
+		</constant>
+		<constant name="ERR_CANT_RESOLVE" value="26" enum="Error">
+			Can't resolve error.
+		</constant>
+		<constant name="ERR_CONNECTION_ERROR" value="27" enum="Error">
+			Connection error.
 		</constant>
 		<constant name="ERR_CANT_ACQUIRE_RESOURCE" value="28" enum="Error">
-			Can't acquire resource error
+			Can't acquire resource error.
+		</constant>
+		<constant name="ERR_CANT_FORK" value="29" enum="Error">
+			Can't fork process error.
 		</constant>
 		<constant name="ERR_INVALID_DATA" value="30" enum="Error">
-			Invalid data error
+			Invalid data error.
 		</constant>
 		<constant name="ERR_INVALID_PARAMETER" value="31" enum="Error">
-			Invalid parameter error
+			Invalid parameter error.
 		</constant>
 		<constant name="ERR_ALREADY_EXISTS" value="32" enum="Error">
-			Already exists error
+			Already exists error.
 		</constant>
 		<constant name="ERR_DOES_NOT_EXIST" value="33" enum="Error">
-			Does not exist error
+			Does not exist error.
 		</constant>
 		<constant name="ERR_DATABASE_CANT_READ" value="34" enum="Error">
-			Database: Read error
+			Database: Read error.
 		</constant>
 		<constant name="ERR_DATABASE_CANT_WRITE" value="35" enum="Error">
-			Database: Write error
+			Database: Write error.
 		</constant>
 		<constant name="ERR_COMPILATION_FAILED" value="36" enum="Error">
-			Compilation failed error
+			Compilation failed error.
 		</constant>
 		<constant name="ERR_METHOD_NOT_FOUND" value="37" enum="Error">
-			Method not found error
+			Method not found error.
 		</constant>
 		<constant name="ERR_LINK_FAILED" value="38" enum="Error">
-			Linking failed error
+			Linking failed error.
 		</constant>
 		<constant name="ERR_SCRIPT_FAILED" value="39" enum="Error">
-			Script failed error
+			Script failed error.
 		</constant>
 		<constant name="ERR_CYCLIC_LINK" value="40" enum="Error">
-			Cycling link (import cycle) error
+			Cycling link (import cycle) error.
+		</constant>
+		<constant name="ERR_INVALID_DECLARATION" value="41" enum="Error">
+			Invalid declaration error.
+		</constant>
+		<constant name="ERR_DUPLICATE_SYMBOL" value="42" enum="Error">
+			Duplicate symbol error.
+		</constant>
+		<constant name="ERR_PARSE_ERROR" value="43" enum="Error">
+			Parse error.
 		</constant>
 		<constant name="ERR_BUSY" value="44" enum="Error">
-			Busy error
+			Busy error.
+		</constant>
+		<constant name="ERR_SKIP" value="45" enum="Error">
+			Skip error.
 		</constant>
 		<constant name="ERR_HELP" value="46" enum="Error">
-			Help error
+			Help error.
 		</constant>
 		<constant name="ERR_BUG" value="47" enum="Error">
-			Bug error
+			Bug error.
+		</constant>
+		<constant name="ERR_PRINTER_ON_FIRE" value="48" enum="Error">
+			Printer on fire error. (This is an easter egg, no engine methods return this error code.)
 		</constant>
 		<constant name="PROPERTY_HINT_NONE" value="0" enum="PropertyHint">
 			No hint for edited property.

+ 3 - 3
modules/gdnative/include/gdnative/gdnative.h

@@ -67,7 +67,7 @@ extern "C" {
 ////// Error
 
 typedef enum {
-	GODOT_OK,
+	GODOT_OK, // (0)
 	GODOT_FAILED, ///< Generic fail error
 	GODOT_ERR_UNAVAILABLE, ///< What is requested is unsupported/unavailable
 	GODOT_ERR_UNCONFIGURED, ///< The object being used hasn't been properly set up yet
@@ -97,12 +97,12 @@ typedef enum {
 	GODOT_ERR_CONNECTION_ERROR,
 	GODOT_ERR_CANT_ACQUIRE_RESOURCE,
 	GODOT_ERR_CANT_FORK,
-	GODOT_ERR_INVALID_DATA, ///< Data passed is invalid	(30)
+	GODOT_ERR_INVALID_DATA, ///< Data passed is invalid (30)
 	GODOT_ERR_INVALID_PARAMETER, ///< Parameter passed is invalid
 	GODOT_ERR_ALREADY_EXISTS, ///< When adding, item already exists
 	GODOT_ERR_DOES_NOT_EXIST, ///< When retrieving/erasing, it item does not exist
 	GODOT_ERR_DATABASE_CANT_READ, ///< database is full
-	GODOT_ERR_DATABASE_CANT_WRITE, ///< database is full	(35)
+	GODOT_ERR_DATABASE_CANT_WRITE, ///< database is full (35)
 	GODOT_ERR_COMPILATION_FAILED,
 	GODOT_ERR_METHOD_NOT_FOUND,
 	GODOT_ERR_LINK_FAILED,