8000 Error handling is not graceful in callback function · Issue #192 · luvit/luv · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Error handling is not graceful in callback function #192

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

Open
mythay opened this issue Nov 16, 2015 · 3 comments
Open

Error handling is not graceful in callback function #192

mythay opened this issue Nov 16, 2015 · 3 comments

Comments

@mythay
Copy link
Contributor
mythay commented Nov 16, 2015

After I have registered a callback to a luv handle, when the callback need to be called, we use luv_call_callback to call it.
It's is OK when there is no exception when calling the callback function. But when error occured, it just print the stack traceback and call exit to end the process.

I think it is better to provide an alternative way just like "uncaughtException" in nodejs to allow user to do more control.

And I think luv_call_callback should to be exported just like "MakeCallback" in NAN, so it can provide a consistent error handling machanism when I write a extension for luv.

@creationix
Copy link
Member

The idea is that error handling will be handled at the lua level instead of at the C level. The fatal exit here is to prevent strange undefined behavior when errors go uncaught.

@creationix
Copy link
Member

After thinking about this for a while, I do think this needs to be handled at the luv level. How exactly does NAN make MakeCallback configurable? My idea is to allow customizing from the lua side a function that intercepts all call stacks:

function luv.makeCallback(fn)
  -- do anything custom here if desired
  return fn
end

And so a custom one would wrap in xpcall and route errors

function luv.makeCallback(fn)
  return function (...)
    local args = {...}
    local success, err = xpcall(function ()
      return fn(unpack(args))
    end, debug.traceback)
    -- TODO: handle success, and err
  end
end

Though I worry about the performance hit from adding all these closures to every event source.

@creationix
Copy link
Member

See #128 for more related ideas.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants
0