From ae28ef327e02ac87ef26f941c401312ed0462d8c Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 6 Apr 2024 11:18:43 +0800 Subject: [PATCH] fix: adjust error message for error in UI event callback (#28200) Also close Nvim instance before removing log file, otherwise the Nvim instance will still write to the log file. Also adjust log level in libuv_process_spawn(). Ref #27660 --- src/nvim/event/libuv_process.c | 2 +- src/nvim/ui.c | 2 +- .../api/server_notifications_spec.lua | 2 ++ .../autocmd/autocmd_oldtest_spec.lua | 2 ++ test/functional/core/startup_spec.lua | 2 ++ test/functional/lua/ui_event_spec.lua | 23 +++++++++++++++++++ test/functional/options/defaults_spec.lua | 6 +++++ test/functional/ui/embed_spec.lua | 2 ++ test/functional/vimscript/server_spec.lua | 2 ++ 9 files changed, 41 insertions(+), 2 deletions(-) diff --git a/src/nvim/event/libuv_process.c b/src/nvim/event/libuv_process.c index 608aeb4c15..f77d686c10 100644 --- a/src/nvim/event/libuv_process.c +++ b/src/nvim/event/libuv_process.c @@ -90,7 +90,7 @@ int libuv_process_spawn(LibuvProcess *uvproc) int status; if ((status = uv_spawn(&proc->loop->uv, &uvproc->uv, &uvproc->uvopts))) { - DLOG("uv_spawn(%s) failed: %s", uvproc->uvopts.file, uv_strerror(status)); + ILOG("uv_spawn(%s) failed: %s", uvproc->uvopts.file, uv_strerror(status)); if (uvproc->uvopts.env) { os_free_fullenv(uvproc->uvopts.env); } diff --git a/src/nvim/ui.c b/src/nvim/ui.c index 506bb93f5b..98751c8952 100644 --- a/src/nvim/ui.c +++ b/src/nvim/ui.c @@ -723,7 +723,7 @@ void ui_call_event(char *name, Array args) handled = true; } if (ERROR_SET(&err)) { - ELOG("Error while executing ui_comp_event callback: %s", err.msg); + ELOG("Error executing UI event callback: %s", err.msg); } api_clear_error(&err); }) diff --git a/test/functional/api/server_notifications_spec.lua b/test/functional/api/server_notifications_spec.lua index d1608a951c..9b411c0c3f 100644 --- a/test/functional/api/server_notifications_spec.lua +++ b/test/functional/api/server_notifications_spec.lua @@ -6,6 +6,7 @@ local api = helpers.api local exec_lua = helpers.exec_lua local retry = helpers.retry local assert_alive = helpers.assert_alive +local check_close = helpers.check_close local testlog = 'Xtest-server-notify-log' @@ -18,6 +19,7 @@ describe('notify', function() end) after_each(function() + check_close() os.remove(testlog) end) diff --git a/test/functional/autocmd/autocmd_oldtest_spec.lua b/test/functional/autocmd/autocmd_oldtest_spec.lua index 279eb495e7..f1d891cddf 100644 --- a/test/functional/autocmd/autocmd_oldtest_spec.lua +++ b/test/functional/autocmd/autocmd_oldtest_spec.lua @@ -8,6 +8,7 @@ local fn = helpers.fn local exec = helpers.exec local feed = helpers.feed local assert_log = helpers.assert_log +local check_close = helpers.check_close local is_os = helpers.is_os local testlog = 'Xtest_autocmd_oldtest_log' @@ -16,6 +17,7 @@ describe('oldtests', function() before_each(clear) after_each(function() + check_close() os.remove(testlog) end) diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index 512b79acc5..bd3db02874 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -32,6 +32,7 @@ local dedent = helpers.dedent local tbl_map = vim.tbl_map local tbl_filter = vim.tbl_filter local endswith = vim.endswith +local check_close = helpers.check_close local testlog = 'Xtest-startupspec-log' @@ -116,6 +117,7 @@ describe('startup', function() before_each(clear) after_each(function() + check_close() os.remove(testlog) end) diff --git a/test/functional/lua/ui_event_spec.lua b/test/functional/lua/ui_event_spec.lua index 3e46018682..39c51d242c 100644 --- a/test/functional/lua/ui_event_spec.lua +++ b/test/functional/lua/ui_event_spec.lua @@ -5,6 +5,10 @@ local exec_lua = helpers.exec_lua local clear = helpers.clear local feed = helpers.feed local fn = helpers.fn +local assert_log = helpers.assert_log +local check_close = helpers.check_close + +local testlog = 'Xtest_lua_ui_event_log' describe('vim.ui_attach', function() local screen @@ -150,3 +154,22 @@ describe('vim.ui_attach', function() }, actual, vim.inspect(actual)) end) end) + +describe('vim.ui_attach', function() + after_each(function() + check_close() + os.remove(testlog) + end) + + it('error in callback is logged', function() + clear({ env = { NVIM_LOG_FILE = testlog } }) + local screen = Screen.new() + screen:attach() + exec_lua([[ + local ns = vim.api.nvim_create_namespace('testspace') + vim.ui_attach(ns, { ext_popupmenu = true }, function() error(42) end) + ]]) + feed('ifoofoobarfo') + assert_log('Error executing UI event callback: Error executing lua: .*: 42', testlog, 100) + end) +end) diff --git a/test/functional/options/defaults_spec.lua b/test/functional/options/defaults_spec.lua index 5e98453565..5bf9aa5ac9 100644 --- a/test/functional/options/defaults_spec.lua +++ b/test/functional/options/defaults_spec.lua @@ -20,6 +20,7 @@ local rmdir = helpers.rmdir local alter_slashes = helpers.alter_slashes local tbl_contains = vim.tbl_contains local expect_exit = helpers.expect_exit +local check_close = helpers.check_close local is_os = helpers.is_os local testlog = 'Xtest-defaults-log' @@ -274,6 +275,7 @@ describe('XDG defaults', function() -- Do not put before_each() here for the same reasons. after_each(function() + check_close() os.remove(testlog) end) @@ -866,6 +868,7 @@ end) describe('stdpath()', function() after_each(function() + check_close() os.remove(testlog) end) @@ -1227,6 +1230,8 @@ describe('stdpath()', function() end) describe('errors', function() + before_each(clear) + it('on unknown strings', function() eq('Vim(call):E6100: "capybara" is not a valid stdpath', exc_exec('call stdpath("capybara")')) eq('Vim(call):E6100: "" is not a valid stdpath', exc_exec('call stdpath("")')) @@ -1242,6 +1247,7 @@ end) describe('autocommands', function() it('closes terminal with default shell on success', function() + clear() api.nvim_set_option_value('shell', helpers.testprg('shell-test'), {}) command('set shellcmdflag=EXIT shellredir= shellpipe= shellquote= shellxquote=') diff --git a/test/functional/ui/embed_spec.lua b/test/functional/ui/embed_spec.lua index 77eae3627d..5a8d6e1f62 100644 --- a/test/functional/ui/embed_spec.lua +++ b/test/functional/ui/embed_spec.lua @@ -14,6 +14,7 @@ local nvim_prog = helpers.nvim_prog local retry = helpers.retry local write_file = helpers.write_file local assert_log = helpers.assert_log +local check_close = helpers.check_close local is_os = helpers.is_os local testlog = 'Xtest-embed-log' @@ -98,6 +99,7 @@ end) describe('--embed UI', function() after_each(function() + check_close() os.remove(testlog) end) diff --git a/test/functional/vimscript/server_spec.lua b/test/functional/vimscript/server_spec.lua index c6c9e9c0ab..7a48633299 100644 --- a/test/functional/vimscript/server_spec.lua +++ b/test/functional/vimscript/server_spec.lua @@ -5,6 +5,7 @@ local clear, fn, api = helpers.clear, helpers.fn, helpers.api local ok = helpers.ok local matches = helpers.matches local pcall_err = helpers.pcall_err +local check_close = helpers.check_close local mkdir = helpers.mkdir local is_os = helpers.is_os @@ -18,6 +19,7 @@ end describe('server', function() after_each(function() + check_close() os.remove(testlog) end)