Skip to content

Commit

Permalink
fix(api): re-route nvim_get_runtime_file errors
Browse files Browse the repository at this point in the history
This allows nvim_get_runtime_file to be properly used via pcall
  • Loading branch information
lewis6991 committed Feb 15, 2022
1 parent 238b944 commit d512be5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/nvim/api/vim.c
Original file line number Diff line number Diff line change
Expand Up @@ -497,8 +497,12 @@ ArrayOf(String) nvim_get_runtime_file(String name, Boolean all, Error *err)

int flags = DIP_DIRFILE | (all ? DIP_ALL : 0);

do_in_runtimepath((char_u *)(name.size ? name.data : ""),
flags, find_runtime_cb, &rv);
TRY_WRAP({
try_start();
do_in_runtimepath((char_u *)(name.size ? name.data : ""),
flags, find_runtime_cb, &rv);
try_end(err);
});
return rv;
}

Expand Down
9 changes: 9 additions & 0 deletions test/functional/api/vim_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ local next_msg = helpers.next_msg
local tmpname = helpers.tmpname
local write_file = helpers.write_file
local exec_lua = helpers.exec_lua
local exc_exec = helpers.exc_exec

local pcall_err = helpers.pcall_err
local format_string = helpers.format_string
Expand Down Expand Up @@ -2240,6 +2241,14 @@ describe('API', function()

eq({}, meths.get_runtime_file("foobarlang/", true))
end)
it('can handle bad patterns', function()
if helpers.pending_win32(pending) then return end

eq("Vim:E220: Missing }.", pcall_err(meths.get_runtime_file, "{", false))

eq('Vim(echo):E5555: API call: Vim:E220: Missing }.',
exc_exec("echo nvim_get_runtime_file('{', v:false)"))
end)
end)

describe('nvim_get_all_options_info', function()
Expand Down

0 comments on commit d512be5

Please sign in to comment.