mirror of
https://github.com/neovim/neovim.git
synced 2025-09-14 15:28:17 +00:00
api/msgpack-rpc: Improve error infrastructure
- Add error type information to `Error` - Rename `set_api_error` to `api_set_error` for consistency with other api_* functions/macros. - Refactor the api_set_error macro to accept formatted strings and error types - Improve error messages - Wrap error messages with gettext macro - Refactor msgpack-rpc serialization to transform Error instances into [type, message] arrays - Add error type information to API metadata - Normalize nvim->client and client->nvim error handling(change channel_send_call to accept an Error pointer instead of the `errored` boolean pointer) - Use macro to initialize Error structures
This commit is contained in:
@@ -12471,25 +12471,18 @@ static void f_rpcrequest(typval_T *argvars, typval_T *rettv)
|
||||
ADD(args, vim_to_object(tv));
|
||||
}
|
||||
|
||||
bool errored;
|
||||
Object result;
|
||||
if (!channel_send_call((uint64_t)argvars[0].vval.v_number,
|
||||
(char *)argvars[1].vval.v_string,
|
||||
args,
|
||||
&result,
|
||||
&errored)) {
|
||||
EMSG2(_(e_invarg2), "Channel doesn't exist");
|
||||
return;
|
||||
}
|
||||
|
||||
if (errored) {
|
||||
vim_report_error(result.data.string);
|
||||
Error err = ERROR_INIT;
|
||||
Object result = channel_send_call((uint64_t)argvars[0].vval.v_number,
|
||||
(char *)argvars[1].vval.v_string,
|
||||
args,
|
||||
&err);
|
||||
if (err.set) {
|
||||
vim_report_error(cstr_as_string(err.msg));
|
||||
goto end;
|
||||
}
|
||||
|
||||
Error conversion_error = {.set = false};
|
||||
if (!object_to_vim(result, rettv, &conversion_error)) {
|
||||
EMSG(_("Error converting the call result"));
|
||||
|
||||
if (!object_to_vim(result, rettv, &err)) {
|
||||
EMSG2(_("Error converting the call result: %s"), err.msg);
|
||||
}
|
||||
|
||||
end:
|
||||
@@ -19442,7 +19435,7 @@ static void script_host_eval(char *method, typval_T *argvars, typval_T *rettv)
|
||||
return;
|
||||
}
|
||||
|
||||
Error err = {.set = false};
|
||||
Error err = ERROR_INIT;
|
||||
object_to_vim(result, rettv, &err);
|
||||
api_free_object(result);
|
||||
|
||||
|
Reference in New Issue
Block a user