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 /src/nvim/api/vimscript.c | |
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 'src/nvim/api/vimscript.c')
-rw-r--r-- | src/nvim/api/vimscript.c | 24 |
1 files changed, 10 insertions, 14 deletions
diff --git a/src/nvim/api/vimscript.c b/src/nvim/api/vimscript.c index 165cc93fbe..0ff2b037ce 100644 --- a/src/nvim/api/vimscript.c +++ b/src/nvim/api/vimscript.c @@ -125,19 +125,17 @@ theend: /// /// On execution error: fails with Vimscript error, updates v:errmsg. /// -/// Prefer using |nvim_cmd()| or |nvim_exec2()| over this. To evaluate multiple lines of Vim script -/// or an Ex command directly, use |nvim_exec2()|. To construct an Ex command using a structured -/// format and then execute it, use |nvim_cmd()|. To modify an Ex command before evaluating it, use -/// |nvim_parse_cmd()| in conjunction with |nvim_cmd()|. +/// Prefer |nvim_cmd()| or |nvim_exec2()| instead. To modify an Ex command in a structured way +/// before executing it, modify the result of |nvim_parse_cmd()| then pass it to |nvim_cmd()|. /// /// @param command Ex command string /// @param[out] err Error details (Vim error), if any void nvim_command(String command, Error *err) FUNC_API_SINCE(1) { - try_start(); - do_cmdline_cmd(command.data); - try_end(err); + TRY_WRAP(err, { + do_cmdline_cmd(command.data); + }); } /// Evaluates a Vimscript |expression|. Dicts and Lists are recursively expanded. @@ -283,13 +281,11 @@ Object nvim_call_dict_function(Object dict, String fn, Array args, Arena *arena, bool mustfree = false; switch (dict.type) { case kObjectTypeString: - try_start(); - if (eval0(dict.data.string.data, &rettv, NULL, &EVALARG_EVALUATE) == FAIL) { - api_set_error(err, kErrorTypeException, - "Failed to evaluate dict expression"); - } - clear_evalarg(&EVALARG_EVALUATE, NULL); - if (try_end(err)) { + TRY_WRAP(err, { + eval0(dict.data.string.data, &rettv, NULL, &EVALARG_EVALUATE); + clear_evalarg(&EVALARG_EVALUATE, NULL); + }); + if (ERROR_SET(err)) { return rv; } // Evaluation of the string arg created a new dict or increased the |