xpcall error handler result gets coerced incorrectly #94
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
When you call
errorinside an xpcall and your error value is not a table, no matter what you return from your error handler, the resulting error will always be turned into a string.You can see the difference between luaj and PUC lua:
This bug prevents the
luaunittest framework from working with luaj: https://luaunit.readthedocs.io/en/luaunit_v3_2_1/but value is an table
Result
It looks like a table, but I think it's just because luaj accidentally called
tostringon the table and returned that. Either that or thetypefunction is blatantly lying.Looks like a string to me!
Its correct with code :
Result
I don't understand what your code is intended to demonstrate. There are no errors involved in that code, so it does not trigger the bug.
My code, which actually does call
error, shows the bug because the return value is coerced in a type which is different from what it should be.Perhaps this would be clearer:
Maybe this
I think (afraid I'm more familiar with LuaJ 2's codebase) the problem occurs here:
daf3da94e3/src/core/org/luaj/vm2/LuaClosure.java (L570)errorHookis the function responsible for calling the xpcall callback. It's being called withgetMessagerather thangetMessageObject, meaning the table is coerced to a string.In my fork, I found it more convenient to manage the stack unwinding and error function handling within the body of
xpcallitself, rather than in the implementation ofLuaClosure. But I fear doing anything different is a bit of a breaking change.Fixed