Improving error messages with bytecode backtracing #1659
Replies: 5 comments 1 reply
-
This has been evaluated before and the answer is no, we would not accept such a PR. Previous request: #1323 |
Beta Was this translation helpful? Give feedback.
-
I noticed the PC and current function are stored in CallInfo (accessible from call info array in lua_State). Are you aware of any implementation details which could prevent implementing backtracing outside the VM? I think it could work if we give a custom error handler to lua_pcall and access the second topmost call info in the handler... A dirty hack obviously but do you see a reason why this couldn't work? |
Beta Was this translation helpful? Give feedback.
-
Why wouldn't an xpcall cover your situation? |
Beta Was this translation helpful? Give feedback.
-
Sorry, you did mention the error handler. |
Beta Was this translation helpful? Give feedback.
-
For tracking the source of "attempt to index/call a nil value" error using bytecode backtracing, I'd need to know the program counter at the location of the error (which I think is 'savedpc' in CallInfo). This is currently not available using lua_getinfo. So I'm thinking of reading the PC and the base address of the bytecode directly from CallInfo in the error handler. I guess there's only one way to find out if it works... P.S. It might not be a bad idea to add the PC and the address of the bytecode to lua_Debug / lua_getinfo for advanced use. Could be useful for implementing bytecode level debugger. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Are you open to PRs that improve error messages such as "attempt to index/call a nil value" using bytecode backtracing?
I'm aware that due to optimizing compiler it may not always be possible, but for some common cases likes import followed by indexing or call I think it should be doable. The goal would be correctness instead of completeness. A downside is that it adds dependency to bytecode format but my gut feeling is that the amount of code required would be reasonable.
We are interested in this because improving the error messages has come up as feedback from our scripters.
By better error messages I mean something like:
foo() --> attempt to call a nil value (global 'foo')
Beta Was this translation helpful? Give feedback.
All reactions