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