-
Notifications
You must be signed in to change notification settings - Fork 173
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
xpcall error handler result gets coerced incorrectly #94
Comments
but value is an table local function err_handler() return {} end
local ok, err = xpcall(function() error({}) end, err_handler)
print("table err", err, type(err))
local ok, err = xpcall(function() error("oh no") end, err_handler)
print("string err", err, type(err)) Result
|
It looks like a table, but I think it's just because luaj accidentally called |
local function err_handler() return {} end
local ok, err = xpcall(function() error({}) end, err_handler)
print("table err", err.gmatch, type(err))
local ok, err = xpcall(function() error("oh no") end, err_handler)
print("string err", err.gmatch, type(err))
Looks like a string to me! |
Its correct with code : local function f (a,b)
return a + b
end
local function err (x)
print ("err called", x)
return "oh no!"
end
local function pcallfun()
return f(1,2)
end
status, err, ret = xpcall (pcallfun, err)
print (status)
print (err)
print (ret) 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 Perhaps this would be clearer: local e = {}
local function err_handler() return e end
local ok, err = xpcall(function() error("oh no") end, err_handler)
print(err == e)
-- $ luaj /tmp/scratch.lua
-- false
-- $ lua5.2 /tmp/scratch.lua
-- true |
Maybe this |
I think (afraid I'm more familiar with LuaJ 2's codebase) the problem occurs here: luaj/src/core/org/luaj/vm2/LuaClosure.java Line 570 in daf3da9
In my fork, I found it more convenient to manage the stack unwinding and error function handling within the body of |
When you call
error
inside 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
luaunit
test framework from working with luaj: https://luaunit.readthedocs.io/en/luaunit_v3_2_1/The text was updated successfully, but these errors were encountered: