mirror of
https://github.com/neovim/neovim.git
synced 2025-09-29 06:28:35 +00:00
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:
@@ -790,10 +790,10 @@ void getout(int exitval)
|
||||
os_exit(exitval);
|
||||
}
|
||||
|
||||
/// Preserve files, print contents of `IObuff`, and exit 1.
|
||||
/// Preserve files, print contents of `errmsg`, and exit 1.
|
||||
///
|
||||
/// May be called from deadly_signal().
|
||||
void preserve_exit(void)
|
||||
void preserve_exit(const char *errmsg)
|
||||
FUNC_ATTR_NORETURN
|
||||
{
|
||||
// 'true' when we are sure to exit, e.g., after a deadly signal
|
||||
@@ -812,12 +812,15 @@ void preserve_exit(void)
|
||||
// Ignore SIGHUP while we are already exiting. #9274
|
||||
signal_reject_deadly();
|
||||
|
||||
if (ui_client_channel_id) {
|
||||
// For TUI: exit alternate screen so that the error messages can be seen.
|
||||
ui_client_stop();
|
||||
}
|
||||
os_errmsg(errmsg);
|
||||
os_errmsg("\n");
|
||||
if (ui_client_channel_id) {
|
||||
os_exit(1);
|
||||
}
|
||||
|
||||
os_errmsg(IObuff);
|
||||
os_errmsg("\n");
|
||||
ui_flush();
|
||||
|
||||
ml_close_notmod(); // close all not-modified buffers
|
||||
|
Reference in New Issue
Block a user