diff --git a/project.godot b/project.godot index 9ba83b5d7c0..a3281c53e35 100644 --- a/project.godot +++ b/project.godot @@ -357,6 +357,7 @@ Export="*res://src/Autoload/Export.gd" Palettes="*res://src/Autoload/Palettes.gd" Keychain="*res://addons/keychain/Keychain.gd" ExtensionsApi="*res://src/Autoload/ExtensionsAPI.gd" +ErrorManager="*res://src/Autoload/ErrorManager.gd" [debug] diff --git a/src/Autoload/ErrorManager.gd b/src/Autoload/ErrorManager.gd new file mode 100644 index 00000000000..619440bf85e --- /dev/null +++ b/src/Autoload/ErrorManager.gd @@ -0,0 +1,108 @@ +extends Node + + +func parse(error: int, start := "", end := ""): + var message: String + match error: + OK: + message = "everything is fine" + FAILED: + message = "Generic error." + ERR_UNAVAILABLE: + message = "Unavailable error." + ERR_UNCONFIGURED: + message = "Unconfigured error." + ERR_UNAUTHORIZED: + message = "Unauthorized error." + ERR_PARAMETER_RANGE_ERROR: + message = "Parameter range error." + ERR_OUT_OF_MEMORY: + message = "Out of memory (OOM) error." + ERR_FILE_NOT_FOUND: + message = "File: Not found error." + ERR_FILE_BAD_DRIVE: + message = "File: Bad drive error." + ERR_FILE_BAD_PATH: + message = "File: Bad path error." + ERR_FILE_NO_PERMISSION: + message = "File: No permission error." + ERR_FILE_ALREADY_IN_USE: + message = "File: Already in use error." + ERR_FILE_CANT_OPEN: + message = "File: Can't open error." + ERR_FILE_CANT_WRITE: + message = "File: Can't write error." + ERR_FILE_CANT_READ: + message = "File: Can't read error." + ERR_FILE_UNRECOGNIZED: + message = "File: Unrecognized error." + ERR_FILE_CORRUPT: + message = "File: Corrupt error." + ERR_FILE_MISSING_DEPENDENCIES: + message = "File: Missing dependencies error." + ERR_FILE_EOF: + message = "File: End of file (EOF) error." + ERR_CANT_OPEN: + message = "Can't open error." + ERR_CANT_CREATE: + message = "Can't create error." + ERR_QUERY_FAILED: + message = "Query failed error." + ERR_ALREADY_IN_USE: + message = "Already in use error." + ERR_LOCKED: + message = "Locked error." + ERR_TIMEOUT: + message = "Timeout error." + ERR_CANT_CONNECT: + message = "Can't connect error." + ERR_CANT_RESOLVE: + message = "Can't resolve error." + ERR_CONNECTION_ERROR: + message = "Connection error." + ERR_CANT_ACQUIRE_RESOURCE: + message = "Can't acquire resource error." + ERR_CANT_FORK: + message = "Can't fork process error." + ERR_INVALID_DATA: + message = "Invalid data error." + ERR_INVALID_PARAMETER: + message = "Invalid parameter error." + ERR_ALREADY_EXISTS: + message = "Already exists error." + ERR_DOES_NOT_EXIST: + message = "Does not exist error." + ERR_DATABASE_CANT_READ: + message = "Database: Read error." + ERR_DATABASE_CANT_WRITE: + message = "Database: Write error." + ERR_COMPILATION_FAILED: + message = "Compilation failed error." + ERR_METHOD_NOT_FOUND: + message = "Method not found error." + ERR_LINK_FAILED: + message = "Linking failed error." + ERR_SCRIPT_FAILED: + message = "Script failed error." + ERR_CYCLIC_LINK: + message = "Cycling link (import cycle) error." + ERR_INVALID_DECLARATION: + message = "Invalid declaration error." + ERR_DUPLICATE_SYMBOL: + message = "Duplicate symbol error." + ERR_PARSE_ERROR: + message = "Parse error." + ERR_BUSY: + message = "Busy error." + ERR_SKIP: + message = "Skip error." + ERR_HELP: + message = "Help error." + ERR_BUG: + message = "Bug error." + ERR_PRINTER_ON_FIRE: +# gdlint: ignore=max-line-length + message = "Printer on fire error. (This is an easter egg, no engine methods return this error code.)" + _: + message = "Unknown error" + return str(start, message, end) diff --git a/src/Autoload/Export.gd b/src/Autoload/Export.gd index d76b5ac5e7e..f91a129cb85 100644 --- a/src/Autoload/Export.gd +++ b/src/Autoload/Export.gd @@ -266,7 +266,12 @@ func export_processed_images( else: var err: int = processed_images[i].save_png(export_paths[i]) if err != OK: - Global.error_dialog.set_text(tr("File failed to save. Error code %s") % err) + Global.error_dialog.set_text( + ( + tr("File failed to save. Error code %s") + % str(err, ErrorManager.parse(err, " (", ")")) + ) + ) Global.error_dialog.popup_centered() Global.dialog_open(true) succeeded = false diff --git a/src/Autoload/OpenSave.gd b/src/Autoload/OpenSave.gd index 562dc0d34b2..3d382a98125 100644 --- a/src/Autoload/OpenSave.gd +++ b/src/Autoload/OpenSave.gd @@ -64,7 +64,10 @@ func handle_loading_file(file: String) -> void: if err != OK: # An error occurred var file_name: String = file.get_file() Global.error_dialog.set_text( - tr("Can't load file '%s'.\nError code: %s") % [file_name, str(err)] + ( + tr("Can't load file '%s'.\nError code: %s") + % [file_name, str(err, ErrorManager.parse(err, " (", ")"))] + ) ) Global.error_dialog.popup_centered() Global.dialog_open(true) @@ -120,7 +123,9 @@ func open_pxo_file(path: String, untitled_backup: bool = false, replace_empty: b err = file.open(path, File.READ) # If the file is not compressed open it raw (pre-v0.7) if err != OK: - Global.error_dialog.set_text(tr("File failed to open. Error code %s") % err) + Global.error_dialog.set_text( + tr("File failed to open. Error code %s") % str(err, ErrorManager.parse(err, " (", ")")) + ) Global.error_dialog.popup_centered() Global.dialog_open(true) file.close() @@ -391,7 +396,11 @@ func save_pxo_file( err = file.open(temp_path, File.WRITE) if err != OK: - Global.error_dialog.set_text(tr("File failed to save. Error code %s") % err) + if temp_path.is_valid_filename(): + return true + Global.error_dialog.set_text( + tr("File failed to save. Error code %s") % str(err, ErrorManager.parse(err, " (", ")")) + ) Global.error_dialog.popup_centered() Global.dialog_open(true) file.close() diff --git a/src/Preferences/HandleExtensions.gd b/src/Preferences/HandleExtensions.gd index 58b31dfa699..fa88fef1210 100644 --- a/src/Preferences/HandleExtensions.gd +++ b/src/Preferences/HandleExtensions.gd @@ -141,7 +141,7 @@ func _add_extension(file_name: String) -> void: var extension_config_file := File.new() var err := extension_config_file.open(extension_config_file_path, File.READ) if err != OK: - print("Error loading config file: ", err) + print("Error loading config file: ", err, ErrorManager.parse(err, " (", ")")) extension_config_file.close() return