diff options
author | luukvbaal <luukvbaal@gmail.com> | 2025-03-21 11:05:01 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-21 03:05:01 -0700 |
commit | c908c2560db891dcd152ed9d3cf10a36179bfed6 (patch) | |
tree | d2601a9fea7fd5d655306cb55b17c666b2f36e0e /test/functional/lua/ui_event_spec.lua | |
parent | fa85543e3b6d4ff4643b460096dda315f145ef89 (diff) | |
download | rneovim-c908c2560db891dcd152ed9d3cf10a36179bfed6.tar.gz rneovim-c908c2560db891dcd152ed9d3cf10a36179bfed6.tar.bz2 rneovim-c908c2560db891dcd152ed9d3cf10a36179bfed6.zip |
fix(log): unify error messages for vim.ui_attach/decor providers #33005
Problem: Error messages that cause a vim.ui_attach() namespace to
detach are not visible in the message history. Decoration
provider and vim.ui_attach error messages are dissimilar.
Solution: Emit vim.ui_attach() errors as an actual message in addition
to logging it. Adjust error message format.
Diffstat (limited to 'test/functional/lua/ui_event_spec.lua')
-rw-r--r-- | test/functional/lua/ui_event_spec.lua | 116 |
1 files changed, 66 insertions, 50 deletions
diff --git a/test/functional/lua/ui_event_spec.lua b/test/functional/lua/ui_event_spec.lua index 5dcb13a7d0..1b3f128b9d 100644 --- a/test/functional/lua/ui_event_spec.lua +++ b/test/functional/lua/ui_event_spec.lua @@ -32,6 +32,7 @@ describe('vim.ui_attach', function() ]] screen = Screen.new(40, 5) + screen:add_extra_attr_ids({ [100] = { bold = true, foreground = Screen.colors.SeaGreen } }) end) local function expect_events(expected) @@ -215,7 +216,7 @@ describe('vim.ui_attach', function() }, messages = { { - content = { { '\nSave changes?\n', 6, 10 } }, + content = { { '\nSave changes?\n', 100, 10 } }, history = false, kind = 'confirm', }, @@ -315,67 +316,63 @@ describe('vim.ui_attach', function() }, }) end) -end) - -describe('vim.ui_attach', function() - local screen - before_each(function() - clear({ env = { NVIM_LOG_FILE = testlog } }) - screen = Screen.new(40, 5) - end) - - after_each(function() - check_close() - os.remove(testlog) - end) - - it('error in callback is logged', function() - exec_lua([[ - local ns = vim.api.nvim_create_namespace('testspace') - vim.ui_attach(ns, { ext_popupmenu = true }, function() error(42) end) - ]]) - feed('ifoo<CR>foobar<CR>fo<C-X><C-N>') - assert_log('Error executing UI event callback: Error executing lua: .*: 42', testlog, 100) - end) it('detaches after excessive errors', function() - screen:add_extra_attr_ids({ [100] = { bold = true, foreground = Screen.colors.SeaGreen } }) + screen:try_resize(86, 10) exec_lua([[ - vim.ui_attach(vim.api.nvim_create_namespace(''), { ext_messages = true }, function() - vim.api.nvim_buf_set_lines(0, -2, -1, false, { err[1] }) + vim.ui_attach(vim.api.nvim_create_namespace(''), { ext_messages = true }, function(ev) + if ev:find('msg') then + vim.api.nvim_buf_set_lines(0, -2, -1, false, { err[1] }) + end end) - ]]) + ]]) local s1 = [[ - ^ | - {1:~ }|*4 + ^ | + {1:~ }|*9 ]] screen:expect(s1) - feed('QQQQQQ<CR>') + feed('Q<CR>') screen:expect({ - grid = [[ - {9:obal 'err' (a nil value)} | - {9:stack traceback:} | - {9: [string "<nvim>"]:2: in function}| - {9: <[string "<nvim>"]:1>} | - {100:Press ENTER or type command to continue}^ | - ]], + grid = s1, messages = { { + content = { { "E354: Invalid register name: '^@'", 9, 6 } }, + history = true, + kind = 'emsg', + }, + { + content = { + { + 'Error executing callback:\n[string "<nvim>"]:3: attempt to index global \'err\' (a nil value)\nstack traceback:\n\t[string "<nvim>"]:3: in function <[string "<nvim>"]:1>', + 9, + 6, + }, + }, + history = true, + kind = 'lua_error', + }, + { content = { { 'Press ENTER or type command to continue', 100, 18 } }, history = false, kind = 'return_prompt', }, }, }) - feed(':1mes clear<CR>:mes<CR>') + feed('<CR>:messages<CR>') screen:expect([[ - | - {3: }| - {9:Excessive errors in vim.ui_attach() call}| - {9:back from ns: 2.} | - {100:Press ENTER or type command to continue}^ | + {9:Error in "msg_show" UI event handler (ns=(UNKNOWN PLUGIN)):} | + {9:Error executing lua: [string "<nvim>"]:3: attempt to index global 'err' (a nil value)} | + {9:stack traceback:} | + {9: [string "<nvim>"]:3: in function <[string "<nvim>"]:1>} | + {9:Error in "msg_clear" UI event handler (ns=(UNKNOWN PLUGIN)):} | + {9:Error executing lua: [string "<nvim>"]:3: attempt to index global 'err' (a nil value)} | + {9:stack traceback:} | + {9: [string "<nvim>"]:3: in function <[string "<nvim>"]:1>} | + {9:Excessive errors in vim.ui_attach() callback (ns=(UNKNOWN PLUGIN))} | + {100:Press ENTER or type command to continue}^ | ]]) - feed('<cr>') + feed('<CR>') + -- Also when scheduled exec_lua([[ vim.ui_attach(vim.api.nvim_create_namespace(''), { ext_messages = true }, function() @@ -414,14 +411,33 @@ describe('vim.ui_attach', function() }, }, }) - feed('<esc>:1mes clear<cr>:mes<cr>') + feed('<Esc>:1messages clear<cr>:messages<CR>') screen:expect([[ - | - {3: }| - {9:Excessive errors in vim.ui_attach() call}| - {9:back from ns: 3.} | - {100:Press ENTER or type command to continue}^ | + ^ | + {1:~ }|*8 + {9:Excessive errors in vim.ui_attach() callback (ns=(UNKNOWN PLUGIN))} | + ]]) + end) +end) + +describe('vim.ui_attach', function() + before_each(function() + clear({ env = { NVIM_LOG_FILE = testlog } }) + end) + + after_each(function() + check_close() + os.remove(testlog) + end) + + it('error in callback is logged', function() + exec_lua([[ + local ns = vim.api.nvim_create_namespace('test') + vim.ui_attach(ns, { ext_popupmenu = true }, function() error(42) end) ]]) + feed('ifoo<CR>foobar<CR>fo<C-X><C-N>') + assert_log('Error in "popupmenu_show" UI event handler %(ns=test%):', testlog, 100) + assert_log('Error executing lua: .*: 42', testlog, 100) end) it('sourcing invalid file does not crash #32166', function() |