From 5c9860a0a2bf27d409c986673f0a74542561c4c3 Mon Sep 17 00:00:00 2001 From: Sander Bosma Date: Wed, 1 Mar 2017 10:43:47 +0100 Subject: api: Do not truncate errors <1 MB. #6237 Closes #5984 --- src/nvim/api/vim.c | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index e5ef4a35c1..bd4a196367 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -188,7 +188,7 @@ Object nvim_eval(String expr, Error *err) typval_T rettv; if (eval0((char_u *)expr.data, &rettv, NULL, true) == FAIL) { - api_set_error(err, Exception, "Failed to evaluate expression"); + _api_set_error(err, kErrorTypeException, "Failed to evaluate expression"); } if (!try_end(err)) { @@ -214,7 +214,7 @@ Object nvim_call_function(String fname, Array args, Error *err) { Object rv = OBJECT_INIT; if (args.size > MAX_FUNC_ARGS) { - api_set_error(err, Validation, + _api_set_error(err, kErrorTypeValidation, _("Function called with too many arguments.")); return rv; } @@ -237,7 +237,7 @@ Object nvim_call_function(String fname, Array args, Error *err) curwin->w_cursor.lnum, curwin->w_cursor.lnum, &dummy, true, NULL, NULL); if (r == FAIL) { - api_set_error(err, Exception, _("Error calling function.")); + _api_set_error(err, kErrorTypeException, _("Error calling function.")); } if (!try_end(err)) { rv = vim_to_object(&rettv); @@ -262,7 +262,7 @@ Integer nvim_strwidth(String str, Error *err) FUNC_API_SINCE(1) { if (str.size > INT_MAX) { - api_set_error(err, Validation, _("String length is too high")); + _api_set_error(err, kErrorTypeValidation, _("String length is too high")); return 0; } @@ -318,7 +318,7 @@ void nvim_set_current_dir(String dir, Error *err) FUNC_API_SINCE(1) { if (dir.size >= MAXPATHL) { - api_set_error(err, Validation, _("Directory string is too long")); + _api_set_error(err, kErrorTypeValidation, _("Directory string is too long")); return; } @@ -330,7 +330,7 @@ void nvim_set_current_dir(String dir, Error *err) if (vim_chdir((char_u *)string, kCdScopeGlobal)) { if (!try_end(err)) { - api_set_error(err, Exception, _("Failed to change directory")); + _api_set_error(err, kErrorTypeException, _("Failed to change directory")); } return; } @@ -538,8 +538,8 @@ void nvim_set_current_buf(Buffer buffer, Error *err) try_start(); int result = do_buffer(DOBUF_GOTO, DOBUF_FIRST, FORWARD, buf->b_fnum, 0); if (!try_end(err) && result == FAIL) { - api_set_error(err, - Exception, + _api_set_error(err, + kErrorTypeException, _("Failed to switch to buffer %d"), buffer); } @@ -591,8 +591,8 @@ void nvim_set_current_win(Window window, Error *err) try_start(); goto_tabpage_win(win_find_tabpage(win), win); if (!try_end(err) && win != curwin) { - api_set_error(err, - Exception, + _api_set_error(err, + kErrorTypeException, _("Failed to switch to window %d"), window); } @@ -645,8 +645,8 @@ void nvim_set_current_tabpage(Tabpage tabpage, Error *err) try_start(); goto_tabpage_tp(tp, true, true); if (!try_end(err) && tp != curtab) { - api_set_error(err, - Exception, + _api_set_error(err, + kErrorTypeException, _("Failed to switch to tabpage %d"), tabpage); } @@ -744,30 +744,30 @@ Array nvim_call_atomic(uint64_t channel_id, Array calls, Error *err) size_t i; // also used for freeing the variables for (i = 0; i < calls.size; i++) { if (calls.items[i].type != kObjectTypeArray) { - api_set_error(err, - Validation, + _api_set_error(err, + kErrorTypeValidation, _("All items in calls array must be arrays")); goto validation_error; } Array call = calls.items[i].data.array; if (call.size != 2) { - api_set_error(err, - Validation, + _api_set_error(err, + kErrorTypeValidation, _("All items in calls array must be arrays of size 2")); goto validation_error; } if (call.items[0].type != kObjectTypeString) { - api_set_error(err, - Validation, + _api_set_error(err, + kErrorTypeValidation, _("name must be String")); goto validation_error; } String name = call.items[0].data.string; if (call.items[1].type != kObjectTypeArray) { - api_set_error(err, - Validation, + _api_set_error(err, + kErrorTypeValidation, _("args must be Array")); goto validation_error; } @@ -794,10 +794,12 @@ Array nvim_call_atomic(uint64_t channel_id, Array calls, Error *err) } else { ADD(rv, NIL); } - return rv; + goto theend; validation_error: api_free_array(results); +theend: + api_free_error(&nested_error); return rv; } -- cgit From 2a49163103827465f25810f5f4e3d4305159f209 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 23 Apr 2017 15:59:59 +0200 Subject: api_clear_error() --- src/nvim/api/vim.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index bd4a196367..2c78ffdec1 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -799,7 +799,7 @@ Array nvim_call_atomic(uint64_t channel_id, Array calls, Error *err) validation_error: api_free_array(results); theend: - api_free_error(&nested_error); + api_clear_error(&nested_error); return rv; } -- cgit From 2ed91f222f1dddda10fbdc9cb80df2be7d4c2da3 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 23 Apr 2017 19:58:13 +0200 Subject: api/internal: Remove `set` field from Error type. --- src/nvim/api/vim.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 2c78ffdec1..924ea419a1 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -165,7 +165,7 @@ String nvim_command_output(String str, Error *err) nvim_command(str, err); do_cmdline_cmd("redir END"); - if (err->set) { + if (ERROR_SET(err)) { return (String) STRING_INIT; } @@ -776,7 +776,7 @@ Array nvim_call_atomic(uint64_t channel_id, Array calls, Error *err) MsgpackRpcRequestHandler handler = msgpack_rpc_get_handler_for(name.data, name.size); Object result = handler.fn(channel_id, args, &nested_error); - if (nested_error.set) { + if (ERROR_SET(&nested_error)) { // error handled after loop break; } @@ -785,7 +785,7 @@ Array nvim_call_atomic(uint64_t channel_id, Array calls, Error *err) } ADD(rv, ARRAY_OBJ(results)); - if (nested_error.set) { + if (ERROR_SET(&nested_error)) { Array errval = ARRAY_DICT_INIT; ADD(errval, INTEGER_OBJ((Integer)i)); ADD(errval, INTEGER_OBJ(nested_error.type)); -- cgit From 3fbc660d57f4726044662bde1bf52c527e45fb98 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 23 Apr 2017 21:54:44 +0200 Subject: api_set_error(): rename --- src/nvim/api/vim.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 924ea419a1..16c630b0e6 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -188,7 +188,7 @@ Object nvim_eval(String expr, Error *err) typval_T rettv; if (eval0((char_u *)expr.data, &rettv, NULL, true) == FAIL) { - _api_set_error(err, kErrorTypeException, "Failed to evaluate expression"); + api_set_error(err, kErrorTypeException, "Failed to evaluate expression"); } if (!try_end(err)) { @@ -214,7 +214,7 @@ Object nvim_call_function(String fname, Array args, Error *err) { Object rv = OBJECT_INIT; if (args.size > MAX_FUNC_ARGS) { - _api_set_error(err, kErrorTypeValidation, + api_set_error(err, kErrorTypeValidation, _("Function called with too many arguments.")); return rv; } @@ -237,7 +237,7 @@ Object nvim_call_function(String fname, Array args, Error *err) curwin->w_cursor.lnum, curwin->w_cursor.lnum, &dummy, true, NULL, NULL); if (r == FAIL) { - _api_set_error(err, kErrorTypeException, _("Error calling function.")); + api_set_error(err, kErrorTypeException, _("Error calling function.")); } if (!try_end(err)) { rv = vim_to_object(&rettv); @@ -262,7 +262,7 @@ Integer nvim_strwidth(String str, Error *err) FUNC_API_SINCE(1) { if (str.size > INT_MAX) { - _api_set_error(err, kErrorTypeValidation, _("String length is too high")); + api_set_error(err, kErrorTypeValidation, _("String length is too high")); return 0; } @@ -318,7 +318,7 @@ void nvim_set_current_dir(String dir, Error *err) FUNC_API_SINCE(1) { if (dir.size >= MAXPATHL) { - _api_set_error(err, kErrorTypeValidation, _("Directory string is too long")); + api_set_error(err, kErrorTypeValidation, _("Directory string is too long")); return; } @@ -330,7 +330,7 @@ void nvim_set_current_dir(String dir, Error *err) if (vim_chdir((char_u *)string, kCdScopeGlobal)) { if (!try_end(err)) { - _api_set_error(err, kErrorTypeException, _("Failed to change directory")); + api_set_error(err, kErrorTypeException, _("Failed to change directory")); } return; } @@ -538,7 +538,7 @@ void nvim_set_current_buf(Buffer buffer, Error *err) try_start(); int result = do_buffer(DOBUF_GOTO, DOBUF_FIRST, FORWARD, buf->b_fnum, 0); if (!try_end(err) && result == FAIL) { - _api_set_error(err, + api_set_error(err, kErrorTypeException, _("Failed to switch to buffer %d"), buffer); @@ -591,7 +591,7 @@ void nvim_set_current_win(Window window, Error *err) try_start(); goto_tabpage_win(win_find_tabpage(win), win); if (!try_end(err) && win != curwin) { - _api_set_error(err, + api_set_error(err, kErrorTypeException, _("Failed to switch to window %d"), window); @@ -645,7 +645,7 @@ void nvim_set_current_tabpage(Tabpage tabpage, Error *err) try_start(); goto_tabpage_tp(tp, true, true); if (!try_end(err) && tp != curtab) { - _api_set_error(err, + api_set_error(err, kErrorTypeException, _("Failed to switch to tabpage %d"), tabpage); @@ -744,21 +744,21 @@ Array nvim_call_atomic(uint64_t channel_id, Array calls, Error *err) size_t i; // also used for freeing the variables for (i = 0; i < calls.size; i++) { if (calls.items[i].type != kObjectTypeArray) { - _api_set_error(err, + api_set_error(err, kErrorTypeValidation, _("All items in calls array must be arrays")); goto validation_error; } Array call = calls.items[i].data.array; if (call.size != 2) { - _api_set_error(err, + api_set_error(err, kErrorTypeValidation, _("All items in calls array must be arrays of size 2")); goto validation_error; } if (call.items[0].type != kObjectTypeString) { - _api_set_error(err, + api_set_error(err, kErrorTypeValidation, _("name must be String")); goto validation_error; @@ -766,7 +766,7 @@ Array nvim_call_atomic(uint64_t channel_id, Array calls, Error *err) String name = call.items[0].data.string; if (call.items[1].type != kObjectTypeArray) { - _api_set_error(err, + api_set_error(err, kErrorTypeValidation, _("args must be Array")); goto validation_error; -- cgit From 086c354a0aad2769042dc91bf5bad021109f56e4 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 23 Apr 2017 22:30:08 +0200 Subject: api: Do not translate error messages. Also re-word some error messages: - "Key does not exist: %s" - "Invalid channel: %" - "Request array size must be 4 (request) or 3 (notification)" - "String cannot contain newlines" References #6150 --- src/nvim/api/vim.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 16c630b0e6..da00fbc6e3 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -166,7 +166,7 @@ String nvim_command_output(String str, Error *err) do_cmdline_cmd("redir END"); if (ERROR_SET(err)) { - return (String) STRING_INIT; + return (String)STRING_INIT; } return cstr_to_string((char *)get_vim_var_str(VV_COMMAND_OUTPUT)); @@ -215,7 +215,7 @@ Object nvim_call_function(String fname, Array args, Error *err) Object rv = OBJECT_INIT; if (args.size > MAX_FUNC_ARGS) { api_set_error(err, kErrorTypeValidation, - _("Function called with too many arguments.")); + "Function called with too many arguments."); return rv; } @@ -237,7 +237,7 @@ Object nvim_call_function(String fname, Array args, Error *err) curwin->w_cursor.lnum, curwin->w_cursor.lnum, &dummy, true, NULL, NULL); if (r == FAIL) { - api_set_error(err, kErrorTypeException, _("Error calling function.")); + api_set_error(err, kErrorTypeException, "Error calling function."); } if (!try_end(err)) { rv = vim_to_object(&rettv); @@ -262,7 +262,7 @@ Integer nvim_strwidth(String str, Error *err) FUNC_API_SINCE(1) { if (str.size > INT_MAX) { - api_set_error(err, kErrorTypeValidation, _("String length is too high")); + api_set_error(err, kErrorTypeValidation, "String length is too high"); return 0; } @@ -318,7 +318,7 @@ void nvim_set_current_dir(String dir, Error *err) FUNC_API_SINCE(1) { if (dir.size >= MAXPATHL) { - api_set_error(err, kErrorTypeValidation, _("Directory string is too long")); + api_set_error(err, kErrorTypeValidation, "Directory string is too long"); return; } @@ -330,7 +330,7 @@ void nvim_set_current_dir(String dir, Error *err) if (vim_chdir((char_u *)string, kCdScopeGlobal)) { if (!try_end(err)) { - api_set_error(err, kErrorTypeException, _("Failed to change directory")); + api_set_error(err, kErrorTypeException, "Failed to change directory"); } return; } @@ -540,7 +540,7 @@ void nvim_set_current_buf(Buffer buffer, Error *err) if (!try_end(err) && result == FAIL) { api_set_error(err, kErrorTypeException, - _("Failed to switch to buffer %d"), + "Failed to switch to buffer %d", buffer); } } @@ -593,7 +593,7 @@ void nvim_set_current_win(Window window, Error *err) if (!try_end(err) && win != curwin) { api_set_error(err, kErrorTypeException, - _("Failed to switch to window %d"), + "Failed to switch to window %d", window); } } @@ -647,7 +647,7 @@ void nvim_set_current_tabpage(Tabpage tabpage, Error *err) if (!try_end(err) && tp != curtab) { api_set_error(err, kErrorTypeException, - _("Failed to switch to tabpage %d"), + "Failed to switch to tabpage %d", tabpage); } } @@ -746,21 +746,21 @@ Array nvim_call_atomic(uint64_t channel_id, Array calls, Error *err) if (calls.items[i].type != kObjectTypeArray) { api_set_error(err, kErrorTypeValidation, - _("All items in calls array must be arrays")); + "All items in calls array must be arrays"); goto validation_error; } Array call = calls.items[i].data.array; if (call.size != 2) { api_set_error(err, kErrorTypeValidation, - _("All items in calls array must be arrays of size 2")); + "All items in calls array must be arrays of size 2"); goto validation_error; } if (call.items[0].type != kObjectTypeString) { api_set_error(err, kErrorTypeValidation, - _("name must be String")); + "Name must be String"); goto validation_error; } String name = call.items[0].data.string; @@ -768,7 +768,7 @@ Array nvim_call_atomic(uint64_t channel_id, Array calls, Error *err) if (call.items[1].type != kObjectTypeArray) { api_set_error(err, kErrorTypeValidation, - _("args must be Array")); + "Args must be Array"); goto validation_error; } Array args = call.items[1].data.array; -- cgit