Describe the project you are working on:
Working on plugins
Describe the problem or limitation you are having in your project:
When something I do in GDScript that results in an error, and I am checking for errors and printing them to the screen, they come out as integers. Because I do not have @GlobalScope's err enums memorized, I must then break my flow of thought from looking at my code to now looking up this enum in documentation to figure out what it means.
It would be more convenient for debugging if error values could be printed directly as a string based on the name of their identifier.
Add a @GDScript.err2str(Error value) -> String method that handles the conversion of integer value to String identifier name for us.
Describe how this feature / enhancement will help you overcome this problem or limitation:
It is purely a convenience factor since a lot of the information people want can already be acquired through manual work. But if we want to improve UX by absolving users of the need to do that, then that would be great.
Show a mock up screenshots/video or a flow diagram explaining how your proposal will work:
if error != OK:
printerr("Error: %d" % error) # shows as int, must look up in docs!
printerr("Error: %s" % err2str(error)) # shows as string, know meaning immediately
Describe implementation detail for your proposal (in code), if possible:
You just need to add a Map<int, String> into the core somewhere and then make it accessible to scripting languages that each implement a global function for accessing the data.
If this enhancement will not be used often, can it be worked around with a few lines of script?:
You could, conceivably, just write your own Dictionary for handling this, but that would be even more work and the whole reason to do this in the first place is to improve the UX, not make it worse.
Is there a reason why this should be core and not an add-on in the asset library?:
See above.
This could be implemented more generic by enabling using GlobalScope in ClassDB methods:
if error != OK:
var error_string = ClassDB.class_get_integer_constant_list("@GlobalScope")[error]
printerr("Error: %s" % error_string)
see godotengine/godot#29972 and godotengine/godot#20015
I think this may possibly be the most beautiful workaround I've ever written: :D
var err = file.open(filepath, File.READ)
if err:
push_error("Failed to open file: %d\n" % [err] +
" See: https://github.com/godotengine/godot/blob/master/core/error_list.h#L%d" % [42+err])
return
It produces output like this:
ERROR: call: Failed to open file: 7
See: https://github.com/godotengine/godot/blob/master/core/error_list.h#L49
At: modules/gdscript/gdscript_functions.cpp:803.
Which leads to: https://github.com/godotengine/godot/blob/master/core/error_list.h#L49
Feel free to use my masterpiece. :D
(Hey, at least I resisted the temptation to make it retrieve & parse the source...)
Most helpful comment
I think this may possibly be the most beautiful workaround I've ever written: :D
It produces output like this:
Which leads to: https://github.com/godotengine/godot/blob/master/core/error_list.h#L49
Feel free to use my masterpiece. :D
(Hey, at least I resisted the temptation to make it retrieve & parse the source...)