mirror of
https://github.com/neovim/neovim.git
synced 2025-10-21 17:21:49 +00:00
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.
This commit is contained in:
@@ -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,51 +316,41 @@ 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,
|
||||
@@ -367,15 +358,21 @@ describe('vim.ui_attach', function()
|
||||
},
|
||||
},
|
||||
})
|
||||
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,15 +411,34 @@ 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()
|
||||
exec_lua([[
|
||||
|
Reference in New Issue
Block a user