Skip to content
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

fix: callback handle error with non-strings #665

Merged
merged 1 commit into from
Aug 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/luv.c
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,8 @@ LUALIB_API int luv_cfpcall(lua_State* L, int nargs, int nresult, int flags) {
break;
case LUA_ERRMEM:
if ((flags & LUVF_CALLBACK_NOERRMSG) == 0)
fprintf(stderr, "System Error: %s\n", lua_tostring(L, -1));
fprintf(stderr, "System Error: %s\n",
luaL_tolstring(L, lua_absindex(L, -1), NULL));
if ((flags & LUVF_CALLBACK_NOEXIT) == 0)
exit(-1);
lua_pop(L, 1);
Expand All @@ -716,7 +717,8 @@ LUALIB_API int luv_cfpcall(lua_State* L, int nargs, int nresult, int flags) {
case LUA_ERRERR:
default:
if ((flags & LUVF_CALLBACK_NOERRMSG) == 0)
fprintf(stderr, "Uncaught Error: %s\n", lua_tostring(L, -1));
fprintf(stderr, "Uncaught Error: %s\n",
luaL_tolstring(L, lua_absindex(L, -1), NULL));
if ((flags & LUVF_CALLBACK_NOEXIT) == 0)
exit(-1);
lua_pop(L, 1);
Expand Down
24 changes: 24 additions & 0 deletions tests/manual-test-cb-non-string-error.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
return require('lib/tap')(function (test)
test("timer callback with errors", function(print, p, expect, uv)
local Error = {}
Error.__index = Error

function Error.new(msg)
local o = setmetatable({}, Error)
o.msg = assert(msg)
return o
end

function Error:__tostring()
return assert(tostring(self.msg))
end

local timer = uv.new_timer()
timer:start(10, 0, function()
timer:stop()
timer:close()
local e = Error.new('Error in timeout callback')
error(e)
end)
end)
end)
Loading