mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
api/internal: Remove set
field from Error type.
This commit is contained in:
parent
62c3f436a9
commit
2ed91f222f
@ -225,7 +225,7 @@ for i = 1, #functions do
|
|||||||
end
|
end
|
||||||
output:write('\n')
|
output:write('\n')
|
||||||
output:write('\n if (args.size != '..#fn.parameters..') {')
|
output:write('\n if (args.size != '..#fn.parameters..') {')
|
||||||
output:write('\n _api_set_error(error, error->type, "Wrong number of arguments: expecting '..#fn.parameters..' but got %zu", args.size);')
|
output:write('\n _api_set_error(error, kErrorTypeException, "Wrong number of arguments: expecting '..#fn.parameters..' but got %zu", args.size);')
|
||||||
output:write('\n goto cleanup;')
|
output:write('\n goto cleanup;')
|
||||||
output:write('\n }\n')
|
output:write('\n }\n')
|
||||||
|
|
||||||
@ -250,7 +250,7 @@ for i = 1, #functions do
|
|||||||
output:write('\n '..converted..' = (handle_T)args.items['..(j - 1)..'].data.integer;')
|
output:write('\n '..converted..' = (handle_T)args.items['..(j - 1)..'].data.integer;')
|
||||||
end
|
end
|
||||||
output:write('\n } else {')
|
output:write('\n } else {')
|
||||||
output:write('\n _api_set_error(error, error->type, "Wrong type for argument '..j..', expecting '..param[1]..'");')
|
output:write('\n _api_set_error(error, kErrorTypeException, "Wrong type for argument '..j..', expecting '..param[1]..'");')
|
||||||
output:write('\n goto cleanup;')
|
output:write('\n goto cleanup;')
|
||||||
output:write('\n }\n')
|
output:write('\n }\n')
|
||||||
else
|
else
|
||||||
@ -290,7 +290,7 @@ for i = 1, #functions do
|
|||||||
output:write('error);\n')
|
output:write('error);\n')
|
||||||
end
|
end
|
||||||
-- and check for the error
|
-- and check for the error
|
||||||
output:write('\n if (error->set) {')
|
output:write('\n if (ERROR_SET(error)) {')
|
||||||
output:write('\n goto cleanup;')
|
output:write('\n goto cleanup;')
|
||||||
output:write('\n }\n')
|
output:write('\n }\n')
|
||||||
else
|
else
|
||||||
|
@ -65,7 +65,7 @@ String buffer_get_line(Buffer buffer, Integer index, Error *err)
|
|||||||
index = convert_index(index);
|
index = convert_index(index);
|
||||||
Array slice = nvim_buf_get_lines(0, buffer, index, index+1, true, err);
|
Array slice = nvim_buf_get_lines(0, buffer, index, index+1, true, err);
|
||||||
|
|
||||||
if (!err->set && slice.size) {
|
if (!ERROR_SET(err) && slice.size) {
|
||||||
rv = slice.items[0].data.string;
|
rv = slice.items[0].data.string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -203,7 +203,7 @@ ArrayOf(String) nvim_buf_get_lines(uint64_t channel_id,
|
|||||||
}
|
}
|
||||||
|
|
||||||
end:
|
end:
|
||||||
if (err->set) {
|
if (ERROR_SET(err)) {
|
||||||
for (size_t i = 0; i < rv.size; i++) {
|
for (size_t i = 0; i < rv.size; i++) {
|
||||||
xfree(rv.items[i].data.string.data);
|
xfree(rv.items[i].data.string.data);
|
||||||
}
|
}
|
||||||
|
@ -8,9 +8,11 @@
|
|||||||
#define ARRAY_DICT_INIT {.size = 0, .capacity = 0, .items = NULL}
|
#define ARRAY_DICT_INIT {.size = 0, .capacity = 0, .items = NULL}
|
||||||
#define STRING_INIT {.data = NULL, .size = 0}
|
#define STRING_INIT {.data = NULL, .size = 0}
|
||||||
#define OBJECT_INIT { .type = kObjectTypeNil }
|
#define OBJECT_INIT { .type = kObjectTypeNil }
|
||||||
#define ERROR_INIT { .set = false, .msg = NULL }
|
#define ERROR_INIT { .type = kErrorTypeNone, .msg = NULL }
|
||||||
#define REMOTE_TYPE(type) typedef handle_T type
|
#define REMOTE_TYPE(type) typedef handle_T type
|
||||||
|
|
||||||
|
#define ERROR_SET(e) ((e)->type != kErrorTypeNone)
|
||||||
|
|
||||||
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
||||||
# define ArrayOf(...) Array
|
# define ArrayOf(...) Array
|
||||||
# define DictionaryOf(...) Dictionary
|
# define DictionaryOf(...) Dictionary
|
||||||
@ -20,6 +22,7 @@ typedef int handle_T;
|
|||||||
|
|
||||||
// Basic types
|
// Basic types
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
kErrorTypeNone = -1,
|
||||||
kErrorTypeException,
|
kErrorTypeException,
|
||||||
kErrorTypeValidation
|
kErrorTypeValidation
|
||||||
} ErrorType;
|
} ErrorType;
|
||||||
@ -39,7 +42,6 @@ typedef enum {
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
ErrorType type;
|
ErrorType type;
|
||||||
char *msg;
|
char *msg;
|
||||||
bool set;
|
|
||||||
} Error;
|
} Error;
|
||||||
|
|
||||||
typedef bool Boolean;
|
typedef bool Boolean;
|
||||||
|
@ -69,7 +69,7 @@ bool try_end(Error *err)
|
|||||||
ET_ERROR,
|
ET_ERROR,
|
||||||
NULL,
|
NULL,
|
||||||
&should_free);
|
&should_free);
|
||||||
_api_set_error(err, err->type, "%s", msg);
|
_api_set_error(err, kErrorTypeException, "%s", msg);
|
||||||
free_global_msglist();
|
free_global_msglist();
|
||||||
|
|
||||||
if (should_free) {
|
if (should_free) {
|
||||||
@ -80,7 +80,7 @@ bool try_end(Error *err)
|
|||||||
discard_current_exception();
|
discard_current_exception();
|
||||||
}
|
}
|
||||||
|
|
||||||
return err->set;
|
return ERROR_SET(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Recursively expands a vimscript value in a dict
|
/// Recursively expands a vimscript value in a dict
|
||||||
@ -803,11 +803,12 @@ void api_free_dictionary(Dictionary value)
|
|||||||
void api_clear_error(Error *value)
|
void api_clear_error(Error *value)
|
||||||
FUNC_ATTR_NONNULL_ALL
|
FUNC_ATTR_NONNULL_ALL
|
||||||
{
|
{
|
||||||
if (!value->set) {
|
if (!ERROR_SET(value)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
xfree(value->msg);
|
xfree(value->msg);
|
||||||
value->msg = NULL;
|
value->msg = NULL;
|
||||||
|
value->type = kErrorTypeNone;
|
||||||
}
|
}
|
||||||
|
|
||||||
Dictionary api_metadata(void)
|
Dictionary api_metadata(void)
|
||||||
@ -953,7 +954,7 @@ static void set_option_value_for(char *key,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (err->set) {
|
if (ERROR_SET(err)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -981,6 +982,7 @@ static void set_option_value_err(char *key,
|
|||||||
void _api_set_error(Error *err, ErrorType errType, const char *format, ...)
|
void _api_set_error(Error *err, ErrorType errType, const char *format, ...)
|
||||||
FUNC_ATTR_NONNULL_ALL
|
FUNC_ATTR_NONNULL_ALL
|
||||||
{
|
{
|
||||||
|
assert(kErrorTypeNone != errType);
|
||||||
va_list args1;
|
va_list args1;
|
||||||
va_list args2;
|
va_list args2;
|
||||||
va_start(args1, format);
|
va_start(args1, format);
|
||||||
@ -994,6 +996,5 @@ void _api_set_error(Error *err, ErrorType errType, const char *format, ...)
|
|||||||
vsnprintf(err->msg, bufsize, format, args2);
|
vsnprintf(err->msg, bufsize, format, args2);
|
||||||
va_end(args2);
|
va_end(args2);
|
||||||
|
|
||||||
err->set = true;
|
|
||||||
err->type = errType;
|
err->type = errType;
|
||||||
}
|
}
|
||||||
|
@ -97,7 +97,7 @@ void nvim_ui_attach(uint64_t channel_id, Integer width, Integer height,
|
|||||||
|
|
||||||
for (size_t i = 0; i < options.size; i++) {
|
for (size_t i = 0; i < options.size; i++) {
|
||||||
ui_set_option(ui, options.items[i].key, options.items[i].value, err);
|
ui_set_option(ui, options.items[i].key, options.items[i].value, err);
|
||||||
if (err->set) {
|
if (ERROR_SET(err)) {
|
||||||
xfree(ui);
|
xfree(ui);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -165,7 +165,7 @@ void nvim_ui_set_option(uint64_t channel_id, String name,
|
|||||||
UI *ui = pmap_get(uint64_t)(connected_uis, channel_id);
|
UI *ui = pmap_get(uint64_t)(connected_uis, channel_id);
|
||||||
|
|
||||||
ui_set_option(ui, name, value, error);
|
ui_set_option(ui, name, value, error);
|
||||||
if (!error->set) {
|
if (!ERROR_SET(error)) {
|
||||||
ui_refresh();
|
ui_refresh();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -165,7 +165,7 @@ String nvim_command_output(String str, Error *err)
|
|||||||
nvim_command(str, err);
|
nvim_command(str, err);
|
||||||
do_cmdline_cmd("redir END");
|
do_cmdline_cmd("redir END");
|
||||||
|
|
||||||
if (err->set) {
|
if (ERROR_SET(err)) {
|
||||||
return (String) STRING_INIT;
|
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,
|
MsgpackRpcRequestHandler handler = msgpack_rpc_get_handler_for(name.data,
|
||||||
name.size);
|
name.size);
|
||||||
Object result = handler.fn(channel_id, args, &nested_error);
|
Object result = handler.fn(channel_id, args, &nested_error);
|
||||||
if (nested_error.set) {
|
if (ERROR_SET(&nested_error)) {
|
||||||
// error handled after loop
|
// error handled after loop
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -785,7 +785,7 @@ Array nvim_call_atomic(uint64_t channel_id, Array calls, Error *err)
|
|||||||
}
|
}
|
||||||
|
|
||||||
ADD(rv, ARRAY_OBJ(results));
|
ADD(rv, ARRAY_OBJ(results));
|
||||||
if (nested_error.set) {
|
if (ERROR_SET(&nested_error)) {
|
||||||
Array errval = ARRAY_DICT_INIT;
|
Array errval = ARRAY_DICT_INIT;
|
||||||
ADD(errval, INTEGER_OBJ((Integer)i));
|
ADD(errval, INTEGER_OBJ((Integer)i));
|
||||||
ADD(errval, INTEGER_OBJ(nested_error.type));
|
ADD(errval, INTEGER_OBJ(nested_error.type));
|
||||||
|
@ -6512,7 +6512,7 @@ static void api_wrapper(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
|||||||
Error err = ERROR_INIT;
|
Error err = ERROR_INIT;
|
||||||
Object result = fn(INTERNAL_CALL, args, &err);
|
Object result = fn(INTERNAL_CALL, args, &err);
|
||||||
|
|
||||||
if (err.set) {
|
if (ERROR_SET(&err)) {
|
||||||
nvim_err_writeln(cstr_as_string(err.msg));
|
nvim_err_writeln(cstr_as_string(err.msg));
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
@ -13784,7 +13784,7 @@ static void f_rpcrequest(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
|||||||
restore_funccal(save_funccalp);
|
restore_funccal(save_funccalp);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (err.set) {
|
if (ERROR_SET(&err)) {
|
||||||
nvim_err_writeln(cstr_as_string(err.msg));
|
nvim_err_writeln(cstr_as_string(err.msg));
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
@ -397,7 +397,7 @@ static void handle_request(Channel *channel, msgpack_object *request)
|
|||||||
Error error = ERROR_INIT;
|
Error error = ERROR_INIT;
|
||||||
msgpack_rpc_validate(&request_id, request, &error);
|
msgpack_rpc_validate(&request_id, request, &error);
|
||||||
|
|
||||||
if (error.set) {
|
if (ERROR_SET(&error)) {
|
||||||
// Validation failed, send response with error
|
// Validation failed, send response with error
|
||||||
if (channel_write(channel,
|
if (channel_write(channel,
|
||||||
serialize_response(channel->id,
|
serialize_response(channel->id,
|
||||||
|
@ -475,7 +475,7 @@ Object msgpack_rpc_handle_missing_method(uint64_t channel_id,
|
|||||||
Array args,
|
Array args,
|
||||||
Error *error)
|
Error *error)
|
||||||
{
|
{
|
||||||
_api_set_error(error, error->type, "Invalid method name");
|
_api_set_error(error, kErrorTypeException, "Invalid method name");
|
||||||
return NIL;
|
return NIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -484,7 +484,7 @@ Object msgpack_rpc_handle_invalid_arguments(uint64_t channel_id,
|
|||||||
Array args,
|
Array args,
|
||||||
Error *error)
|
Error *error)
|
||||||
{
|
{
|
||||||
_api_set_error(error, error->type, "Invalid method arguments");
|
_api_set_error(error, kErrorTypeException, "Invalid method arguments");
|
||||||
return NIL;
|
return NIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -517,7 +517,7 @@ void msgpack_rpc_serialize_response(uint64_t response_id,
|
|||||||
msgpack_pack_int(pac, 1);
|
msgpack_pack_int(pac, 1);
|
||||||
msgpack_pack_uint64(pac, response_id);
|
msgpack_pack_uint64(pac, response_id);
|
||||||
|
|
||||||
if (err->set) {
|
if (ERROR_SET(err)) {
|
||||||
// error represented by a [type, message] array
|
// error represented by a [type, message] array
|
||||||
msgpack_pack_array(pac, 2);
|
msgpack_pack_array(pac, 2);
|
||||||
msgpack_rpc_from_integer(err->type, pac);
|
msgpack_rpc_from_integer(err->type, pac);
|
||||||
|
Loading…
Reference in New Issue
Block a user