refactor(exit): pass error message to preserve_exit() (#22097)

Problem:
1. Some calls to preserve_exit() don't put a message in IObuff, so the
   IObuff printed by preserve_exit() contains unrelated information.
2. If a TUI client runs out of memory or receives a deadly signal, the
   error message is shown on alternate screen and cannot be easily seen
   because the TUI exits alternate screen soon afterwards.

Solution:
Pass error message to preserve_exit() and exit alternate screen before
printing it.

Note that this doesn't fix the problem that server error messages cannot
be easily seen on exit. This is tracked in #21608 and #21843.
This commit is contained in:
zeertzjq
2023-02-04 20:14:31 +08:00
committed by GitHub
parent 90333b24c3
commit 69bb145cea
8 changed files with 21 additions and 30 deletions

View File

@@ -211,9 +211,7 @@ static int nlua_luv_cfpcall(lua_State *lstate, int nargs, int nresult, int flags
if (status) {
if (status == LUA_ERRMEM && !(flags & LUVF_CALLBACK_NOEXIT)) {
// consider out of memory errors unrecoverable, just like xmalloc()
os_errmsg(e_outofmem);
os_errmsg("\n");
preserve_exit();
preserve_exit(e_outofmem);
}
const char *error = lua_tostring(lstate, -1);