Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Error elaborator #891

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
108 changes: 108 additions & 0 deletions src/Autoload/ErrorManager.gd
Original file line number Diff line number Diff line change
@@ -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)
7 changes: 6 additions & 1 deletion src/Autoload/Export.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 12 additions & 3 deletions src/Autoload/OpenSave.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/Preferences/HandleExtensions.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down