Report last error in closing methods

When there are multiple errors around closing methods, report the
last error instead of the original.
This commit is contained in:
Roberto Ierusalimschy
2020-12-22 10:54:25 -03:00
parent f9d29b0c44
commit 0ceada8da9
5 changed files with 35 additions and 101 deletions

View File

@@ -75,8 +75,11 @@ static int luaB_auxwrap (lua_State *L) {
int r = auxresume(L, co, lua_gettop(L));
if (r < 0) { /* error? */
int stat = lua_status(co);
if (stat != LUA_OK && stat != LUA_YIELD) /* error in the coroutine? */
lua_resetthread(co); /* close its tbc variables */
if (stat != LUA_OK && stat != LUA_YIELD) { /* error in the coroutine? */
stat = lua_resetthread(co); /* close its tbc variables */
lua_assert(stat != LUA_OK);
lua_xmove(co, L, 1); /* copy error message */
}
if (stat != LUA_ERRMEM && /* not a memory error and ... */
lua_type(L, -1) == LUA_TSTRING) { /* ... error object is a string? */
luaL_where(L, 1); /* add extra info, if available */