-
-
Notifications
You must be signed in to change notification settings - Fork 165
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
Consider using xpcall in try block #1478
Comments
Unfortunately, it is not as simple as replacing e.g.
would return:
instead of the correct/JS behavior
This can possibly be solved by changing the way we throw string literals. Another solution might be to create a custom/adapted implementation of debug.tracepack. |
Likely the best middle ground is that an empty catch block can compile to an xpcall, and a non-empty one can compile as-is. Same with un-caught rejected promise objects, if they don't already work that way. |
TypeScriptToLua/src/lualib/Await.ts Lines 55 to 58 in 16a8eb3
coroutine.resume also lack of stack trace, the asyncCoroutine should pass into debug.traceback as the first argument to get the error trace in coroutine context.
|
-- Reimplemented pcall function
_G.pcall = function(func, ...)
local results = table.pack(
xpcall(func, function(err)
-- Do nothing here, just return the error object
return err..'\n'..debug.traceback()
end, ...)
)
local status = table.remove(results, 1)
if not status then
-- When an error occurs, err is the error message, mimicking the behavior of pcall
return false, table.unpack(results)
else
-- No error occurred, return all the additional parameters returned by xpcall
return true, table.unpack(results)
end
end We can use |
Error message from pcall only include the first line that error happened but not the full stack traceback, but this can be done by compiling to using
xpcall
and passdebug.traceback
as second arg:Although custom plugin can implement this feature, but plugin can not rewrite lualib such as pcall in Promise.lua
The text was updated successfully, but these errors were encountered: