From c9f3174075a7168f10fabf806891ef59ee3b13d4 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Mon, 7 May 2018 03:24:01 +0200 Subject: API: return non-generic VimL errors - Return VimL errors instead of generic errors for: - nvim_call_function - nvim_call_dict_function - Fix tests which were silently broken before this change. This violates #6150 where we agreed not to translate API errors. But that can be fixed later. --- src/nvim/eval.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index cc29496968..3c408a4381 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -6241,20 +6241,21 @@ bool set_ref_in_func(char_u *name, ufunc_T *fp_in, int copyID) /// invoked function uses them. It is called like this: /// new_argcount = argv_func(current_argcount, argv, called_func_argcount) /// -/// Return FAIL when the function can't be called, OK otherwise. -/// Also returns OK when an error was encountered while executing the function. +/// @return FAIL if function cannot be called, else OK (even if an error +/// occurred while executing the function! Use `msg_first_ignored_err` +/// to get the error) int call_func( const char_u *funcname, // name of the function int len, // length of "name" - typval_T *rettv, // return value goes here + typval_T *rettv, // [out] value goes here int argcount_in, // number of "argvars" typval_T *argvars_in, // vars for arguments, must have "argcount" // PLUS ONE elements! ArgvFunc argv_func, // function to fill in argvars linenr_T firstline, // first line of range linenr_T lastline, // last line of range - int *doesrange, // return: function handled range + int *doesrange, // [out] function handled range bool evaluate, partial_T *partial, // optional, can be NULL dict_T *selfdict_in // Dictionary for "self" @@ -6428,21 +6429,25 @@ call_func( return ret; } -/* - * Give an error message with a function name. Handle things. - * "ermsg" is to be passed without translation, use N_() instead of _(). - */ +/// Give an error message with a function name. Handle things. +/// +/// @param ermsg must be passed without translation (use N_() instead of _()). +/// @param name function name static void emsg_funcname(char *ermsg, char_u *name) { - char_u *p; + char_u *p; - if (*name == K_SPECIAL) + if (*name == K_SPECIAL) { p = concat_str((char_u *)"", name + 3); - else + } else { p = name; + } + EMSG2(_(ermsg), p); - if (p != name) + + if (p != name) { xfree(p); + } } /* -- cgit From 32b0470b03b3892a4ed6c4bfec0d4a5527d996b1 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Wed, 9 May 2018 03:02:12 +0200 Subject: API: better way to capture abort-causing non-exception errors This condition is not perfectly reliable: (did_emsg && force_abort && !current_exception) The more proper way to check for abort-causing non-exception errors is to set up `msg_list` using the "pattern" given by do_cmdline(). --- src/nvim/eval.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 3c408a4381..45a1776c86 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -6242,8 +6242,8 @@ bool set_ref_in_func(char_u *name, ufunc_T *fp_in, int copyID) /// new_argcount = argv_func(current_argcount, argv, called_func_argcount) /// /// @return FAIL if function cannot be called, else OK (even if an error -/// occurred while executing the function! Use `msg_first_ignored_err` -/// to get the error) +/// occurred while executing the function! Set `msg_list` to capture +/// the error, see do_cmdline()). int call_func( const char_u *funcname, // name of the function -- cgit