api: Implement vim_report_error function

This function is used to report errors caused by remote functions called by
channel_send_call
This commit is contained in:
Thiago de Arruda 2014-09-11 10:35:52 -03:00
parent d29b62daab
commit 15ca58d79f
3 changed files with 20 additions and 12 deletions

View File

@ -308,6 +308,16 @@ void vim_err_write(String str)
write_msg(str, true);
}
/// Higher level error reporting function that ensures all str contents
/// are written by sending a trailing linefeed to `vim_wrr_write`
///
/// @param str The message
void vim_report_error(String str)
{
vim_err_write(str);
vim_err_write((String) {.data = "\n", .size = 1});
}
/// Gets the current list of buffer handles
///
/// @return The number of buffers

View File

@ -12796,13 +12796,17 @@ static void f_send_call(typval_T *argvars, typval_T *rettv)
return;
}
if (errored) {
vim_report_error(result.data.string);
goto end;
}
Error conversion_error = {.set = false};
if (errored || !object_to_vim(result, rettv, &conversion_error)) {
EMSG(errored ?
result.data.string.data :
_("Error converting the call result"));
if (!object_to_vim(result, rettv, &conversion_error)) {
EMSG(_("Error converting the call result"));
}
end:
api_free_object(result);
}

View File

@ -102,7 +102,7 @@ Object provider_call(char *method, Array args)
sizeof(buf),
"Provider for method \"%s\" is not available",
method);
report_error(buf);
vim_report_error(cstr_as_string(buf));
api_free_array(args);
return NIL;
}
@ -112,7 +112,7 @@ Object provider_call(char *method, Array args)
channel_send_call(f->channel_id, method, args, &result, &error);
if (error) {
report_error(result.data.string.data);
vim_report_error(result.data.string);
api_free_object(result);
return NIL;
}
@ -151,9 +151,3 @@ static Feature * find_feature(char *name)
return NULL;
}
static void report_error(char *str)
{
vim_err_write((String) {.data = str, .size = strlen(str)});
vim_err_write((String) {.data = "\n", .size = 1});
}