lua-users home
lua-l archive

Re: Lua 5.3: assert non-string values in #2 cause `(no error message)`-style error message

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Am 20.10.2014 um 06:46 schröbte Andrew Starks:
local success, p_res = assert(p(11))
--> C:\lua.exe: (no error message)
```
I don't know if this has broad potential for others, or not, but an error
would be welcomed here, as well. This time for having any value that is not
a string or `nil` in assert's second argument would have saved me hours of
head scratching.
It's not `assert`'s fault. `error{}` without an explicit `pcall` has the same "(no error message)" effect. (And some people _want_ to use `assert` with non-string error messages ...)
Not having a line number/file name was very...difficult.
The place where bad things happen is the `msghandler` function in `lua.c`. It replaces any non-string errors with strings, but also doesn't add a stack trace in this case (which it could since the original error value is discarded anyway).
You could add
 msg = lua_tostring(L, -1);
 if (msg)
 luaL_traceback(L, L, msg, 1);
after the `lua_pushliteral` call in `msghandler`. (I'd prefer it that `msghandler` leaves all to-string conversions to the `report` function, though.)
--Andrew
Philipp

AltStyle によって変換されたページ (->オリジナル) /