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
LuaJIT 5.1: Exceptions are not rethrown through sol::error #28
Comments
With a bit more testing, it seems to actually segfault the entire thread, which is odd. What's happening is that it is throwing try
{
lua.script(script);
}
catch (...)
{
std::cout << "Caught (...)" << std::endl;
FAIL("wat");
} It fails with There's a few options here:
I tested this on Linux for gcc-4.9 and clang36, didn't check other platforms. |
We do (1) already in the latest. The only place we actually throw a |
It.. seems to work properly, but I'm using Windows x64. I assume it works properly on other x64-platforms. Support for exceptions, as the tables on the page for extensions/exceptions displays, depends on your platform. I have made it so every function bound through The exception wrapping can be turned off with SOL_NO_EXCEPTIONS being defined, but I only just added it and I'm still writing the docs. |
If you mean that we should be catching ALL errors, including ones that we can't catch with |
So this was fixed in the latest edition? That's awesome, let me try it out for myself. I wasn't sure if it was something you were investigating with your recent changes to exceptions. |
I'm going to assume this is fixed and closed it now. If something else goes entirely derelict, re-open it ASAP and I'll get on it (maybe even get a few Vagrant files to spin things up). |
I actually can't verify that it's working. 👎 sol::state lua;
// should error
// REQUIRE_THROWS_AS(lua.script(script), sol::error);
try
{
lua.script("local M = require(\"M\")\n"
"assert(M.foo() == \"foo\")\n");
} catch (sol::error& e)
{
std::cout << "caught sol::error: " << e.what() << std::endl;
}
catch (std::runtime_error& e)
{
FAIL("caught std::runtime_error: " << e.what());
}
catch (std::exception& e)
{
FAIL("caught std::exception: " << e.what());
}
catch (const char* e)
{
FAIL("caught char*: " << e);
}
catch (...)
{
try {
auto eptr = std::current_exception();
if (eptr)
std::rethrow_exception(eptr);
else
FAIL("caught(...)");
} catch (std::exception& e)
{
FAIL("caught (...): " << e.what());
}
} It fails with SOL_LUA_VERSION=501 |
Yup, needs to be reopened: https://travis-ci.org/Nava2/sol2/jobs/113445378 |
RIP, and it fails on a regular linux container too. I'm not really running a linux build, just using g++/clang++ on a Windows machine... buh. I'll have to install an actual 64-bit linux at some point. |
I've been doing development against all three, but recently, since making this Vagrantfile, I've been using the |
So, this is a tad troubling, but I'm not sure what I can do about it. I've wrapped every function call in a trampoline, and even This is not something that's really within our control, unfortunately. Unless you can spot out any bright ideas, this seems like one of those "Well, it's your burden for using luajit." |
Does the error reproduce on newer version so LuaJIT? I haven't tried, but I will now. I fear it might come down to, as you said, "known problems." I'm surprised about this since the site does say that it should work as we expect on Linux. It's supposed to have full interoperability with C++ exceptions on Linux. |
I'm using 2.0.4, which last I checked is the latest. |
Yeah, I just verified as well. I'm not sure what to say about that. It stinks, but it is definitely able to be written around. |
Guess we just file bugs in |
I think it's more of a "report to mailing list," but yeah. I think there needs to be a test case created without sol first, though. |
Unfortunately, we'll have to close this. :( I'll be sure to throw over a issue on the LuaJit Github, which is apparently the active place of development. |
Sounds good to me.. unfortunately. Where is the repository? E: Nevermind.. https://github.com/LuaJIT/LuaJIT |
One solution is to have exception-throwing C++ functions wrapped in functions that store |
The reason LuaJIT has issues is that, unlike PUC-Lua, LuaJIT is not written in the common subset of C and C++, but rather in C + assembler. LuaJIT must therefore handle unwinding manually, hence the lack of portability. |
There's nothing we can do about this. If LuaJIT hits its own while performing basic VM tasks (not withing a C Function, we trampoline those appropriately), errors and calls atpanic and the atpanic throws, LuaJIT will not respect the thrown error on most platforms. If we simply return the error message or the exception in a userdata, it doesn't matter because LuaJIT -- like vanilla Lua -- will call I am not interested in re-inventing exceptions with some weird longjmp bullshit because LuaJIT does not keep its promises on 64-bit Linux. |
Is there a way to catch lua exceptions using sol on luajit x86 (windows x64)? Simple |
|
@ThePhD |
For what it's worth, you can define |
In my code, I'm trying to force some sandboxing, one part of this is setting the
require
function tonil
.To test this, I create an "library script":
I store this into a file in the test dir,
m.lua
, and then load it via:On Lua 5.2, this throws a sol::error claiming the
require
function isnil
. This is the expected behaviour, however, luajit exceptions are never caught and it throws an error unrecognized.The text was updated successfully, but these errors were encountered: