-
-
Notifications
You must be signed in to change notification settings - Fork 658
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
[lua] exit code 0 in case of error #10979
Comments
I suspect the issue is that the entry-point is wrapped in a Lines 2147 to 2160 in 8d4f2d7
haxe/std/lua/_lua/_hx_tostring.lua Lines 103 to 112 in 8d4485b
|
@jdonaldson @inklit @tobil4sk @RealyUniqueName since worked on the Lua target I'd like to ask for your opinion on what would the best way to solve this. I can provide a PR but I am unsure about the right approach. Any help is highly appreciated. |
I've done very minimal work with the lua target, but I think it would be fine just to add a |
I could imagine the reason why this was added is that lua scripts often don't run stand alone but are plugins inside other programs. so if we add os. exit() and a lua script is used in an embedded lua interpreter and then not only that lua plugin fails but the whole app may crash/exit. So I wonder if we couldn't just remove the whole error handling so the error can bubble up and the callee can decide what to do. |
I guess one way to solve this is to have a compiler flag that controls whether this extra error handling is added. This way, it works both for embeddable scripts and for standalone scripts. Really, all it does it it makes uncaught exceptions more readable in the terminal:
vs
|
Compiler flag sounds like a reasonable idea. Any suggestions? Something like |
|
Alright, I created a PR. Can you please have a look. |
Yeah, I'll go through PRs tomorrow, just did issues today and I missed some with linked PRs. |
I think we can close this, now that #11008 is merged. |
I decided to have another look at this, because I got curious why without the error handler function haxe programs print out this unreadable mess:
So I read up on how lua handles error values: http://www.lua.org/manual/5.4/manual.html#7 @sebthom I then had another look at your original suggestion of rethrowing the error, so I modified the error handler to return a new error object with __tostring() which just returns the exception message along with the traceback() value. Then I changed the main code to rethrow the error if the main xpcall returns an error. So now, the original error message and call stack are preserved for both uncaught haxe exceptions and uncaught native exceptions. This method solves the original problem of returning the correct error code, without compromising on error message readability and without using _G.os.exit, so it is safer and should work for both embedded scripts and for standalone scripts, making the flag redundant. Let me know what you think: #11082 (Also, for reference the reason the stack trace is missing from custom errors by default is because of: http://lua-users.org/lists/lua-l/2014-10/msg00115.html. This is why we need the custom error handler.) |
* [lua] Clean up uncaught error handling Removes usage of os.exit, which makes it safer and applicable both to lua scripts embedded in another application and standalone scripts. This removes the need for the lua-standalone flag. * [lua] Mark Exception.toString with @:keep If it is dce'd, we get a mess when lua prints an uncaught error * [lua] Prevent error handler polluting error stack * Add tests for #10979 * Prevent test failures on lua 5.1 Lua 5.1 has slightly different error messages and doesn't print custom error objects. * Minor fix
A failing Haxe program targeting/running on Lua will exit with error code 0 instead of a non-zero exit code. For all other targets an unhandled error/exception will result in a non-zero exit code.
Example:
Tested with Haxe 4.2.5, Lua 5.2.4 on Windows 10.
The text was updated successfully, but these errors were encountered: