diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2024-12-16 08:34:16 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-16 08:34:16 -0800 |
commit | 022449b5223659d515b78bada7de2fac8718820a (patch) | |
tree | 2ce4dd7b21d2ba4089308b877608f4dbc4166d99 /test/functional/api/vim_spec.lua | |
parent | fb8372adb3b9f50d4d18eba6f650c3728353ab00 (diff) | |
download | rneovim-022449b5223659d515b78bada7de2fac8718820a.tar.gz rneovim-022449b5223659d515b78bada7de2fac8718820a.tar.bz2 rneovim-022449b5223659d515b78bada7de2fac8718820a.zip |
fix(api): generic error messages, not using TRY_WRAP #31596
Problem:
- API functions using `try_start` directly, do not surface the
underlying error message, and instead show generic messages.
- Error-handling code is duplicated in the API impl.
- Failure modes are not tested.
Solution:
- Use `TRY_WRAP`.
- Add tests.
Diffstat (limited to 'test/functional/api/vim_spec.lua')
-rw-r--r-- | test/functional/api/vim_spec.lua | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 2eeb5c18a1..879df690d1 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -695,7 +695,7 @@ describe('API', function() pcall_err(request, 'nvim_call_dict_function', 42, 'f', { 1, 2 }) ) eq( - 'Failed to evaluate dict expression', + 'Vim:E121: Undefined variable: foo', pcall_err(request, 'nvim_call_dict_function', 'foo', 'f', { 1, 2 }) ) eq('dict not found', pcall_err(request, 'nvim_call_dict_function', '42', 'f', { 1, 2 })) @@ -1957,6 +1957,16 @@ describe('API', function() api.nvim_set_current_win(api.nvim_list_wins()[2]) eq(api.nvim_list_wins()[2], api.nvim_get_current_win()) end) + + it('failure modes', function() + n.command('split') + + eq('Invalid window id: 9999', pcall_err(api.nvim_set_current_win, 9999)) + + -- XXX: force nvim_set_current_win to fail somehow. + n.command("au WinLeave * throw 'foo'") + eq('WinLeave Autocommands for "*": foo', pcall_err(api.nvim_set_current_win, 1000)) + end) end) describe('nvim_{get,set}_current_tabpage, nvim_list_tabpages', function() @@ -1976,6 +1986,16 @@ describe('API', function() eq(api.nvim_list_tabpages()[2], api.nvim_get_current_tabpage()) eq(api.nvim_list_wins()[2], api.nvim_get_current_win()) end) + + it('failure modes', function() + n.command('tabnew') + + eq('Invalid tabpage id: 999', pcall_err(api.nvim_set_current_tabpage, 999)) + + -- XXX: force nvim_set_current_tabpage to fail somehow. + n.command("au TabLeave * throw 'foo'") + eq('TabLeave Autocommands for "*": foo', pcall_err(api.nvim_set_current_tabpage, 1)) + end) end) describe('nvim_get_mode', function() |