summaryrefslogtreecommitdiff
path: root/src/channel.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/channel.c')
-rw-r--r--src/channel.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/channel.c b/src/channel.c
index 811d87ae1..a6458c65e 100644
--- a/src/channel.c
+++ b/src/channel.c
@@ -853,24 +853,31 @@ channel_exe_cmd(int idx, char_u *cmd, typval_T *arg2, typval_T *arg3)
{
typval_T *tv;
typval_T err_tv;
- char_u *json;
+ char_u *json = NULL;
/* Don't pollute the display with errors. */
++emsg_skip;
tv = eval_expr(arg, NULL);
- --emsg_skip;
if (is_eval)
{
- if (tv == NULL)
+ if (tv != NULL)
+ json = json_encode_nr_expr(arg3->vval.v_number, tv);
+ if (tv == NULL || (json != NULL && *json == NUL))
{
+ /* If evaluation failed or the result can't be encoded
+ * then return the string "ERROR". */
err_tv.v_type = VAR_STRING;
err_tv.vval.v_string = (char_u *)"ERROR";
tv = &err_tv;
+ json = json_encode_nr_expr(arg3->vval.v_number, tv);
+ }
+ if (json != NULL)
+ {
+ channel_send(idx, json, "eval");
+ vim_free(json);
}
- json = json_encode_nr_expr(arg3->vval.v_number, tv);
- channel_send(idx, json, "eval");
- vim_free(json);
}
+ --emsg_skip;
if (tv != &err_tv)
free_tv(tv);
}