aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/api/vim.c
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2018-05-09 03:23:18 +0200
committerJustin M. Keyes <justinkz@gmail.com>2018-05-09 23:18:39 +0200
commit2326a4ac3a9dfdedba6fd4e1c68491b071fdc57b (patch)
tree2a87e90020b121becc43f017b193967065b69cd5 /src/nvim/api/vim.c
parent32b0470b03b3892a4ed6c4bfec0d4a5527d996b1 (diff)
downloadrneovim-2326a4ac3a9dfdedba6fd4e1c68491b071fdc57b.tar.gz
rneovim-2326a4ac3a9dfdedba6fd4e1c68491b071fdc57b.tar.bz2
rneovim-2326a4ac3a9dfdedba6fd4e1c68491b071fdc57b.zip
API: nvim_eval(): return non-generic VimL errors
Use the same pattern as nvim_call_function (_call_function).
Diffstat (limited to 'src/nvim/api/vim.c')
-rw-r--r--src/nvim/api/vim.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c
index 7f8c10fcd1..1f7f13c831 100644
--- a/src/nvim/api/vim.c
+++ b/src/nvim/api/vim.c
@@ -268,11 +268,30 @@ theend:
Object nvim_eval(String expr, Error *err)
FUNC_API_SINCE(1)
{
+ static int recursive = 0; // recursion depth
Object rv = OBJECT_INIT;
+
+ // `msg_list` controls the collection of abort-causing non-exception errors,
+ // which would otherwise be ignored. This pattern is from do_cmdline().
+ struct msglist **saved_msg_list = msg_list;
+ struct msglist *private_msg_list;
+ msg_list = &private_msg_list;
+ private_msg_list = NULL;
+
+ // Initialize `force_abort` and `suppress_errthrow` at the top level.
+ if (!recursive) {
+ force_abort = false;
+ suppress_errthrow = false;
+ current_exception = NULL;
+ // `did_emsg` is set by emsg(), which cancels execution.
+ did_emsg = false;
+ }
+ recursive++;
try_start();
typval_T rettv;
if (eval0((char_u *)expr.data, &rettv, NULL, true) == FAIL) {
+ // This generic error should be overwritten by try_end() since #8371.
api_set_error(err, kErrorTypeException, "Failed to evaluate expression");
}
@@ -281,6 +300,8 @@ Object nvim_eval(String expr, Error *err)
}
tv_clear(&rettv);
+ msg_list = saved_msg_list; // Restore the exception context.
+ recursive--;
return rv;
}