mirror of
https://github.com/neovim/neovim.git
synced 2025-09-07 03:48:18 +00:00
API: include invalid buffer/window/tabpage in error message (#11712)
This commit is contained in:
@@ -631,7 +631,7 @@ buf_T *find_buffer_by_handle(Buffer buffer, Error *err)
|
||||
buf_T *rv = handle_get_buffer(buffer);
|
||||
|
||||
if (!rv) {
|
||||
api_set_error(err, kErrorTypeValidation, "Invalid buffer id");
|
||||
api_set_error(err, kErrorTypeValidation, "Invalid buffer id: %d", buffer);
|
||||
}
|
||||
|
||||
return rv;
|
||||
@@ -646,7 +646,7 @@ win_T *find_window_by_handle(Window window, Error *err)
|
||||
win_T *rv = handle_get_window(window);
|
||||
|
||||
if (!rv) {
|
||||
api_set_error(err, kErrorTypeValidation, "Invalid window id");
|
||||
api_set_error(err, kErrorTypeValidation, "Invalid window id: %d", window);
|
||||
}
|
||||
|
||||
return rv;
|
||||
@@ -661,7 +661,7 @@ tabpage_T *find_tab_by_handle(Tabpage tabpage, Error *err)
|
||||
tabpage_T *rv = handle_get_tabpage(tabpage);
|
||||
|
||||
if (!rv) {
|
||||
api_set_error(err, kErrorTypeValidation, "Invalid tabpage id");
|
||||
api_set_error(err, kErrorTypeValidation, "Invalid tabpage id: %d", tabpage);
|
||||
}
|
||||
|
||||
return rv;
|
||||
|
@@ -24,6 +24,10 @@ describe('api/tabpage', function()
|
||||
nvim('set_current_win', win3)
|
||||
eq(win3, tabpage('get_win', tab2))
|
||||
end)
|
||||
|
||||
it('validates args', function()
|
||||
eq('Invalid tabpage id: 23', pcall_err(tabpage, 'list_wins', 23))
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('{get,set,del}_var', function()
|
||||
|
@@ -55,8 +55,8 @@ describe('API/win', function()
|
||||
end)
|
||||
|
||||
it('validates args', function()
|
||||
eq('Invalid buffer id', pcall_err(window, 'set_buf', nvim('get_current_win'), 23))
|
||||
eq('Invalid window id', pcall_err(window, 'set_buf', 23, nvim('get_current_buf')))
|
||||
eq('Invalid buffer id: 23', pcall_err(window, 'set_buf', nvim('get_current_win'), 23))
|
||||
eq('Invalid window id: 23', pcall_err(window, 'set_buf', 23, nvim('get_current_buf')))
|
||||
end)
|
||||
end)
|
||||
|
||||
@@ -73,7 +73,7 @@ describe('API/win', function()
|
||||
|
||||
it('does not leak memory when using invalid window ID with invalid pos',
|
||||
function()
|
||||
eq('Invalid window id', pcall_err(meths.win_set_cursor, 1, {"b\na"}))
|
||||
eq('Invalid window id: 1', pcall_err(meths.win_set_cursor, 1, {"b\na"}))
|
||||
end)
|
||||
|
||||
it('updates the screen, and also when the window is unfocused', function()
|
||||
|
@@ -219,7 +219,7 @@ describe('autocmd', function()
|
||||
eq(7, eval('g:test'))
|
||||
|
||||
-- API calls are blocked when aucmd_win is not in scope
|
||||
eq('Vim(call):E5555: API call: Invalid window id',
|
||||
eq('Vim(call):E5555: API call: Invalid window id: 1001',
|
||||
pcall_err(command, "call nvim_set_current_win(g:winid)"))
|
||||
|
||||
-- second time aucmd_win is needed, a different code path is invoked
|
||||
@@ -257,7 +257,7 @@ describe('autocmd', function()
|
||||
eq(0, eval('g:had_value'))
|
||||
eq(7, eval('g:test'))
|
||||
|
||||
eq('Vim(call):E5555: API call: Invalid window id',
|
||||
eq('Vim(call):E5555: API call: Invalid window id: 1001',
|
||||
pcall_err(command, "call nvim_set_current_win(g:winid)"))
|
||||
end)
|
||||
|
||||
|
@@ -44,7 +44,7 @@ describe('eval-API', function()
|
||||
eq('Vim(call):E5555: API call: Wrong type for argument 1, expecting Buffer', err)
|
||||
|
||||
err = exc_exec('call nvim_buf_line_count(17)')
|
||||
eq('Vim(call):E5555: API call: Invalid buffer id', err)
|
||||
eq('Vim(call):E5555: API call: Invalid buffer id: 17', err)
|
||||
end)
|
||||
|
||||
|
||||
|
@@ -39,7 +39,7 @@ describe('luaeval(vim.api.…)', function()
|
||||
eq({false, 'Argument "pos" must be a [row, col] array'},
|
||||
funcs.luaeval('{pcall(vim.api.nvim_win_set_cursor, 0, {1, 2, 3})}'))
|
||||
-- Used to produce a memory leak due to a bug in nvim_win_set_cursor
|
||||
eq({false, 'Invalid window id'},
|
||||
eq({false, 'Invalid window id: -1'},
|
||||
funcs.luaeval('{pcall(vim.api.nvim_win_set_cursor, -1, {1, 2, 3})}'))
|
||||
end)
|
||||
|
||||
|
@@ -47,7 +47,7 @@ describe(':lua command', function()
|
||||
pcall_err(command, 'lua ()'))
|
||||
eq([[Vim(lua):E5108: Error executing lua [string ":lua"]:1: TEST]],
|
||||
exc_exec('lua error("TEST")'))
|
||||
eq([[Vim(lua):E5108: Error executing lua [string ":lua"]:1: Invalid buffer id]],
|
||||
eq([[Vim(lua):E5108: Error executing lua [string ":lua"]:1: Invalid buffer id: -10]],
|
||||
exc_exec('lua vim.api.nvim_buf_set_lines(-10, 1, 1, false, {"TEST"})'))
|
||||
eq({''}, curbufmeths.get_lines(0, 100, false))
|
||||
end)
|
||||
|
Reference in New Issue
Block a user