gilzoide / godot-lua-pluginscript

Godot PluginScript for the Lua language, currently based on LuaJIT's FFI
https://gilzoide.github.io/godot-lua-pluginscript/topics/README.md.html
MIT License
308 stars 21 forks source link

Fix mangled error message format #45

Closed jtbx closed 1 year ago

jtbx commented 1 year ago

When you get a Lua error in the Godot debugger, the error message includes newlines and control characters which get rendered as question mark symbols and make the message look mangled.

I just changed the error format to a simpler one-liner that will most likely fit on one's screen and not look broken.

Before and after: Before and after image

I have only tested this on Linux (linux64) but in theory it should work on all platforms.

Thank you for maintaining this project!

gilzoide commented 1 year ago

Hi @jtbx, thanks for the contribution!

Originally, I used this long message to show stacktrace information in the same manner as Lua does. I totally agree that this format is quite horrible to look at in the Godot editor, but losing the full stacktrace makes debugging quite harder if the error happens in deeply nested functions.

I was testing here to see what GDScript does, and it stops at a breakpoint automatically, so we have the full stacktrace and access to the state from within the editor. When running from standalone builds, it prints the error as a "SCRIPT ERROR" and gives a single line of stack trace, so it might be ok to lose the full stacktrace information.

I don't know yet if Godot supports stopping at breakpoints in PluginScripts on errors. I know there is an interface for debugging, which Lua PluginScript doesn't implement yet, but never tested it out. Nothing that you should worry about, I'm just saying.

I'd like to maintain the stack trace, if possible, while we don't have debug callbacks in editor. If you have any ideas on this, please comment.

jtbx commented 1 year ago

I think a good idea would be to put the error as the message and the stack trace in the hover text so that one can hover over the error message to get the stack trace but not have the stack trace in the main message. Is this possible?

We could do what GDScript does with a bit of work but I don't know much at all about the GDNative/Godot API.

gilzoide commented 1 year ago

Hey @jtbx, I'm really sorry about the delay.

I think a good idea would be to put the error as the message and the stack trace in the hover text so that one can hover over the error message to get the stack trace but not have the stack trace in the main message. Is this possible?

Without changing the Godot editor code, I doubt it. At least in the PluginScript API there doesn't seem to have anything like that.

We could do what GDScript does with a bit of work but I don't know much at all about the GDNative/Godot API.

Yeah, I guess this would be ideal. There are some debugging/profile callbacks in the PluginScript API, but I ended up never trying them.

Anyway, I think we can go with your implementation, I guess people will likely be using the Godot editor for debugging instead of standalone builds.

jtbx commented 1 year ago

Alright, sounds good. Will you be using the debugger for errors in lua-gdextension?

gilzoide commented 1 year ago

Alright, sounds good. Will you be using the debugger for errors in lua-gdextension?

When the time comes, yes, we should definitely implement debug callbacks in Lua GDExtension. I just didn't work on it in Lua PluginScript because I ended up prioritizing other stuff and never came back for it =/