Skip to content

Instantly share code, notes, and snippets.

@duckinator
Last active April 15, 2020 15:23
Show Gist options
  • Save duckinator/fa9b3109eb8a2f1ce13707de30b1a2de to your computer and use it in GitHub Desktop.
Save duckinator/fa9b3109eb8a2f1ce13707de30b1a2de to your computer and use it in GitHub Desktop.
Godot script to allow getting (more) friendly messages for errors.
extends RigidBody
# Called when the node enters the scene tree for the first time.
func _ready():
player = get_parent().get_node('Player')
var timer = Timer.new()
timer.set_one_shot(true)
timer.set_wait_time(5)
var err = timer.connect("timeoutt", self, "cleanup")
if err != OK:
Error.print_info(err)
add_child(timer)
timer.start()
Invalid parameter error. (ERR_INVALID_PARAMETER)
Frame 0 - res://Error.gd:7 in function 'print_info'
Frame 1 - res://Bullet.gd:15 in function '_ready'
Frame 2 - res://Player.gd:41 in function 'action_primary'
Frame 3 - res://Player.gd:114 in function 'process_input'
Frame 4 - res://Player.gd:74 in function '_physics_process'
# Generated by generate_error.sh
extends Node
func print_info(err):
printerr(info(err))
print_stack()
func name(err):
var error_names = {}
error_names[FAILED] = "FAILED"
error_names[ERR_UNAVAILABLE] = "ERR_UNAVAILABLE"
error_names[ERR_UNCONFIGURED] = "ERR_UNCONFIGURED"
error_names[ERR_UNAUTHORIZED] = "ERR_UNAUTHORIZED"
error_names[ERR_PARAMETER_RANGE_ERROR] = "ERR_PARAMETER_RANGE_ERROR"
error_names[ERR_OUT_OF_MEMORY] = "ERR_OUT_OF_MEMORY"
error_names[ERR_FILE_NOT_FOUND] = "ERR_FILE_NOT_FOUND"
error_names[ERR_FILE_BAD_DRIVE] = "ERR_FILE_BAD_DRIVE"
error_names[ERR_FILE_BAD_PATH] = "ERR_FILE_BAD_PATH"
error_names[ERR_FILE_NO_PERMISSION] = "ERR_FILE_NO_PERMISSION"
error_names[ERR_FILE_ALREADY_IN_USE] = "ERR_FILE_ALREADY_IN_USE"
error_names[ERR_FILE_CANT_OPEN] = "ERR_FILE_CANT_OPEN"
error_names[ERR_FILE_CANT_WRITE] = "ERR_FILE_CANT_WRITE"
error_names[ERR_FILE_CANT_READ] = "ERR_FILE_CANT_READ"
error_names[ERR_FILE_UNRECOGNIZED] = "ERR_FILE_UNRECOGNIZED"
error_names[ERR_FILE_CORRUPT] = "ERR_FILE_CORRUPT"
error_names[ERR_FILE_MISSING_DEPENDENCIES] = "ERR_FILE_MISSING_DEPENDENCIES"
error_names[ERR_FILE_EOF] = "ERR_FILE_EOF"
error_names[ERR_CANT_OPEN] = "ERR_CANT_OPEN"
error_names[ERR_CANT_CREATE] = "ERR_CANT_CREATE"
error_names[ERR_QUERY_FAILED] = "ERR_QUERY_FAILED"
error_names[ERR_ALREADY_IN_USE] = "ERR_ALREADY_IN_USE"
error_names[ERR_LOCKED] = "ERR_LOCKED"
error_names[ERR_TIMEOUT] = "ERR_TIMEOUT"
#error_names[ERR_CANT_CONNECT] = "ERR_CANT_CONNECT"
#error_names[ERR_CANT_RESOLVE] = "ERR_CANT_RESOLVE"
#error_names[ERR_CONNECTION_ERROR] = "ERR_CONNECTION_ERROR"
error_names[ERR_CANT_ACQUIRE_RESOURCE] = "ERR_CANT_ACQUIRE_RESOURCE"
#error_names[ERR_CANT_FORK] = "ERR_CANT_FORK"
error_names[ERR_INVALID_DATA] = "ERR_INVALID_DATA"
error_names[ERR_INVALID_PARAMETER] = "ERR_INVALID_PARAMETER"
error_names[ERR_ALREADY_EXISTS] = "ERR_ALREADY_EXISTS"
error_names[ERR_DOES_NOT_EXIST] = "ERR_DOES_NOT_EXIST"
error_names[ERR_DATABASE_CANT_READ] = "ERR_DATABASE_CANT_READ"
error_names[ERR_DATABASE_CANT_WRITE] = "ERR_DATABASE_CANT_WRITE"
error_names[ERR_COMPILATION_FAILED] = "ERR_COMPILATION_FAILED"
error_names[ERR_METHOD_NOT_FOUND] = "ERR_METHOD_NOT_FOUND"
error_names[ERR_LINK_FAILED] = "ERR_LINK_FAILED"
error_names[ERR_SCRIPT_FAILED] = "ERR_SCRIPT_FAILED"
error_names[ERR_CYCLIC_LINK] = "ERR_CYCLIC_LINK"
#error_names[ERR_INVALID_DECLARATION] = "ERR_INVALID_DECLARATION"
#error_names[ERR_DUPLICATE_SYMBOL] = "ERR_DUPLICATE_SYMBOL"
error_names[ERR_PARSE_ERROR] = "ERR_PARSE_ERROR"
error_names[ERR_BUSY] = "ERR_BUSY"
#error_names[ERR_SKIP] = "ERR_SKIP"
error_names[ERR_HELP] = "ERR_HELP"
error_names[ERR_BUG] = "ERR_BUG"
#error_names[ERR_PRINTER_ON_FIRE] = "ERR_PRINTER_ON_FIRE"
return error_names[err]
func message(err):
var error_messages = {}
error_messages[FAILED] = "Generic error."
error_messages[ERR_UNAVAILABLE] = "Unavailable error."
error_messages[ERR_UNCONFIGURED] = "Unconfigured error."
error_messages[ERR_UNAUTHORIZED] = "Unauthorized error."
error_messages[ERR_PARAMETER_RANGE_ERROR] = "Parameter range error."
error_messages[ERR_OUT_OF_MEMORY] = "Out of memory (OOM) error."
error_messages[ERR_FILE_NOT_FOUND] = "File: Not found error."
error_messages[ERR_FILE_BAD_DRIVE] = "File: Bad drive error."
error_messages[ERR_FILE_BAD_PATH] = "File: Bad path error."
error_messages[ERR_FILE_NO_PERMISSION] = "File: No permission error."
error_messages[ERR_FILE_ALREADY_IN_USE] = "File: Already in use error."
error_messages[ERR_FILE_CANT_OPEN] = "File: Can’t open error."
error_messages[ERR_FILE_CANT_WRITE] = "File: Can’t write error."
error_messages[ERR_FILE_CANT_READ] = "File: Can’t read error."
error_messages[ERR_FILE_UNRECOGNIZED] = "File: Unrecognized error."
error_messages[ERR_FILE_CORRUPT] = "File: Corrupt error."
error_messages[ERR_FILE_MISSING_DEPENDENCIES] = "File: Missing dependencies error."
error_messages[ERR_FILE_EOF] = "File: End of file (EOF) error."
error_messages[ERR_CANT_OPEN] = "Can’t open error."
error_messages[ERR_CANT_CREATE] = "Can’t create error."
error_messages[ERR_QUERY_FAILED] = "Query failed error."
error_messages[ERR_ALREADY_IN_USE] = "Already in use error."
error_messages[ERR_LOCKED] = "Locked error."
error_messages[ERR_TIMEOUT] = "Timeout error."
#error_messages[ERR_CANT_CONNECT] = "Can’t connect error."
#error_messages[ERR_CANT_RESOLVE] = "Can’t resolve error."
#error_messages[ERR_CONNECTION_ERROR] = "Connection error."
error_messages[ERR_CANT_ACQUIRE_RESOURCE] = "Can’t acquire resource error."
#error_messages[ERR_CANT_FORK] = "Can’t fork process error."
error_messages[ERR_INVALID_DATA] = "Invalid data error."
error_messages[ERR_INVALID_PARAMETER] = "Invalid parameter error."
error_messages[ERR_ALREADY_EXISTS] = "Already exists error."
error_messages[ERR_DOES_NOT_EXIST] = "Does not exist error."
error_messages[ERR_DATABASE_CANT_READ] = "Database: Read error."
error_messages[ERR_DATABASE_CANT_WRITE] = "Database: Write error."
error_messages[ERR_COMPILATION_FAILED] = "Compilation failed error."
error_messages[ERR_METHOD_NOT_FOUND] = "Method not found error."
error_messages[ERR_LINK_FAILED] = "Linking failed error."
error_messages[ERR_SCRIPT_FAILED] = "Script failed error."
error_messages[ERR_CYCLIC_LINK] = "Cycling link (import cycle) error."
#error_messages[ERR_INVALID_DECLARATION] = "Invalid declaration error."
#error_messages[ERR_DUPLICATE_SYMBOL] = "Duplicate symbol error."
error_messages[ERR_PARSE_ERROR] = "Parse error."
error_messages[ERR_BUSY] = "Busy error."
#error_messages[ERR_SKIP] = "Skip error."
error_messages[ERR_HELP] = "Help error."
error_messages[ERR_BUG] = "Bug error."
#error_messages[ERR_PRINTER_ON_FIRE] = "Printer on fire error. (This is an easter egg, no engine methods return this error code.)"
return error_messages[err]
func info(err):
return message(err) + ' (' + name(err) + ')'
FAILED = 1 — Generic error.
ERR_UNAVAILABLE = 2 — Unavailable error.
ERR_UNCONFIGURED = 3 — Unconfigured error.
ERR_UNAUTHORIZED = 4 — Unauthorized error.
ERR_PARAMETER_RANGE_ERROR = 5 — Parameter range error.
ERR_OUT_OF_MEMORY = 6 — Out of memory (OOM) error.
ERR_FILE_NOT_FOUND = 7 — File: Not found error.
ERR_FILE_BAD_DRIVE = 8 — File: Bad drive error.
ERR_FILE_BAD_PATH = 9 — File: Bad path error.
ERR_FILE_NO_PERMISSION = 10 — File: No permission error.
ERR_FILE_ALREADY_IN_USE = 11 — File: Already in use error.
ERR_FILE_CANT_OPEN = 12 — File: Can’t open error.
ERR_FILE_CANT_WRITE = 13 — File: Can’t write error.
ERR_FILE_CANT_READ = 14 — File: Can’t read error.
ERR_FILE_UNRECOGNIZED = 15 — File: Unrecognized error.
ERR_FILE_CORRUPT = 16 — File: Corrupt error.
ERR_FILE_MISSING_DEPENDENCIES = 17 — File: Missing dependencies error.
ERR_FILE_EOF = 18 — File: End of file (EOF) error.
ERR_CANT_OPEN = 19 — Can’t open error.
ERR_CANT_CREATE = 20 — Can’t create error.
ERR_QUERY_FAILED = 21 — Query failed error.
ERR_ALREADY_IN_USE = 22 — Already in use error.
ERR_LOCKED = 23 — Locked error.
ERR_TIMEOUT = 24 — Timeout error.
ERR_CANT_CONNECT = 25 — Can’t connect error.
ERR_CANT_RESOLVE = 26 — Can’t resolve error.
ERR_CONNECTION_ERROR = 27 — Connection error.
ERR_CANT_ACQUIRE_RESOURCE = 28 — Can’t acquire resource error.
ERR_CANT_FORK = 29 — Can’t fork process error.
ERR_INVALID_DATA = 30 — Invalid data error.
ERR_INVALID_PARAMETER = 31 — Invalid parameter error.
ERR_ALREADY_EXISTS = 32 — Already exists error.
ERR_DOES_NOT_EXIST = 33 — Does not exist error.
ERR_DATABASE_CANT_READ = 34 — Database: Read error.
ERR_DATABASE_CANT_WRITE = 35 — Database: Write error.
ERR_COMPILATION_FAILED = 36 — Compilation failed error.
ERR_METHOD_NOT_FOUND = 37 — Method not found error.
ERR_LINK_FAILED = 38 — Linking failed error.
ERR_SCRIPT_FAILED = 39 — Script failed error.
ERR_CYCLIC_LINK = 40 — Cycling link (import cycle) error.
ERR_INVALID_DECLARATION = 41 — Invalid declaration error.
ERR_DUPLICATE_SYMBOL = 42 — Duplicate symbol error.
ERR_PARSE_ERROR = 43 — Parse error.
ERR_BUSY = 44 — Busy error.
ERR_SKIP = 45 — Skip error.
ERR_HELP = 46 — Help error.
ERR_BUG = 47 — Bug error.
ERR_PRINTER_ON_FIRE = 48 — Printer on fire error. (This is an easter egg, no engine methods return this error code.)
#!/bin/bash
# NOTE: You *will* have to comment out some things. I'm not sure why.
printf "# Generated by generate_error.sh\n\n" > Error.gd
printf "extends Node\n\n" >> Error.gd
printf "func print_info(err):\n\tprinterr(info(err))\n\tprint_stack()\n\n" >> Error.gd
printf "func name(err):\n\tvar error_names = {}\n" >> Error.gd
sed 's/ \(.*\) = [0-9][0-9]\? — \(.*\)/\terror_names[\1] = "\1"/' errors.txt >> Error.gd
printf "\treturn error_names[err]\n\n" >> Error.gd
printf "func message(err):\n\tvar error_messages = {}\n" >> Error.gd
sed 's/ \(.*\) = [0-9][0-9]\? — \(.*\)/\terror_messages[\1] = "\2"/' errors.txt >> Error.gd
printf "\treturn error_messages[err]\n\n" >> Error.gd
printf "func info(err):\n" >> Error.gd
printf "\treturn message(err) + ' (' + name(err) + ')'\n" >> Error.gd
# rm -f src/Error.gd
# mv Error.gd src/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment