aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2017-04-23 19:58:13 +0200
committerJustin M. Keyes <justinkz@gmail.com>2017-04-23 23:44:32 +0200
commit2ed91f222f1dddda10fbdc9cb80df2be7d4c2da3 (patch)
treea5448dfc1bd0440167cdfad4e3041ca1548bbf52 /src
parent62c3f436a96e2102ec5c1e3af974c8e57fe4e76c (diff)
downloadrneovim-2ed91f222f1dddda10fbdc9cb80df2be7d4c2da3.tar.gz
rneovim-2ed91f222f1dddda10fbdc9cb80df2be7d4c2da3.tar.bz2
rneovim-2ed91f222f1dddda10fbdc9cb80df2be7d4c2da3.zip
api/internal: Remove `set` field from Error type.
Diffstat (limited to 'src')
-rw-r--r--src/nvim/api/buffer.c4
-rw-r--r--src/nvim/api/private/defs.h6
-rw-r--r--src/nvim/api/private/helpers.c11
-rw-r--r--src/nvim/api/ui.c4
-rw-r--r--src/nvim/api/vim.c6
-rw-r--r--src/nvim/eval.c4
-rw-r--r--src/nvim/msgpack_rpc/channel.c2
-rw-r--r--src/nvim/msgpack_rpc/helpers.c6
8 files changed, 23 insertions, 20 deletions
diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c
index 81d25d7c95..cffc7a2e38 100644
--- a/src/nvim/api/buffer.c
+++ b/src/nvim/api/buffer.c
@@ -65,7 +65,7 @@ String buffer_get_line(Buffer buffer, Integer index, Error *err)
index = convert_index(index);
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;
}
@@ -203,7 +203,7 @@ ArrayOf(String) nvim_buf_get_lines(uint64_t channel_id,
}
end:
- if (err->set) {
+ if (ERROR_SET(err)) {
for (size_t i = 0; i < rv.size; i++) {
xfree(rv.items[i].data.string.data);
}
diff --git a/src/nvim/api/private/defs.h b/src/nvim/api/private/defs.h
index a07422bd12..60bf38265f 100644
--- a/src/nvim/api/private/defs.h
+++ b/src/nvim/api/private/defs.h
@@ -8,9 +8,11 @@
#define ARRAY_DICT_INIT {.size = 0, .capacity = 0, .items = NULL}
#define STRING_INIT {.data = NULL, .size = 0}
#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 ERROR_SET(e) ((e)->type != kErrorTypeNone)
+
#ifdef INCLUDE_GENERATED_DECLARATIONS
# define ArrayOf(...) Array
# define DictionaryOf(...) Dictionary
@@ -20,6 +22,7 @@ typedef int handle_T;
// Basic types
typedef enum {
+ kErrorTypeNone = -1,
kErrorTypeException,
kErrorTypeValidation
} ErrorType;
@@ -39,7 +42,6 @@ typedef enum {
typedef struct {
ErrorType type;
char *msg;
- bool set;
} Error;
typedef bool Boolean;
diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c
index 3bf584ff2f..58534d78a0 100644
--- a/src/nvim/api/private/helpers.c
+++ b/src/nvim/api/private/helpers.c
@@ -69,7 +69,7 @@ bool try_end(Error *err)
ET_ERROR,
NULL,
&should_free);
- _api_set_error(err, err->type, "%s", msg);
+ _api_set_error(err, kErrorTypeException, "%s", msg);
free_global_msglist();
if (should_free) {
@@ -80,7 +80,7 @@ bool try_end(Error *err)
discard_current_exception();
}
- return err->set;
+ return ERROR_SET(err);
}
/// Recursively expands a vimscript value in a dict
@@ -803,11 +803,12 @@ void api_free_dictionary(Dictionary value)
void api_clear_error(Error *value)
FUNC_ATTR_NONNULL_ALL
{
- if (!value->set) {
+ if (!ERROR_SET(value)) {
return;
}
xfree(value->msg);
value->msg = NULL;
+ value->type = kErrorTypeNone;
}
Dictionary api_metadata(void)
@@ -953,7 +954,7 @@ static void set_option_value_for(char *key,
break;
}
- if (err->set) {
+ if (ERROR_SET(err)) {
return;
}
@@ -981,6 +982,7 @@ static void set_option_value_err(char *key,
void _api_set_error(Error *err, ErrorType errType, const char *format, ...)
FUNC_ATTR_NONNULL_ALL
{
+ assert(kErrorTypeNone != errType);
va_list args1;
va_list args2;
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);
va_end(args2);
- err->set = true;
err->type = errType;
}
diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c
index 534274db0f..4c39bc57eb 100644
--- a/src/nvim/api/ui.c
+++ b/src/nvim/api/ui.c
@@ -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++) {
ui_set_option(ui, options.items[i].key, options.items[i].value, err);
- if (err->set) {
+ if (ERROR_SET(err)) {
xfree(ui);
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_set_option(ui, name, value, error);
- if (!error->set) {
+ if (!ERROR_SET(error)) {
ui_refresh();
}
}
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));
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index 1e174712a3..d7feed8bfd 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -6512,7 +6512,7 @@ static void api_wrapper(typval_T *argvars, typval_T *rettv, FunPtr fptr)
Error err = ERROR_INIT;
Object result = fn(INTERNAL_CALL, args, &err);
- if (err.set) {
+ if (ERROR_SET(&err)) {
nvim_err_writeln(cstr_as_string(err.msg));
goto end;
}
@@ -13784,7 +13784,7 @@ static void f_rpcrequest(typval_T *argvars, typval_T *rettv, FunPtr fptr)
restore_funccal(save_funccalp);
}
- if (err.set) {
+ if (ERROR_SET(&err)) {
nvim_err_writeln(cstr_as_string(err.msg));
goto end;
}
diff --git a/src/nvim/msgpack_rpc/channel.c b/src/nvim/msgpack_rpc/channel.c
index bd7f84fed9..36a3210c70 100644
--- a/src/nvim/msgpack_rpc/channel.c
+++ b/src/nvim/msgpack_rpc/channel.c
@@ -397,7 +397,7 @@ static void handle_request(Channel *channel, msgpack_object *request)
Error error = ERROR_INIT;
msgpack_rpc_validate(&request_id, request, &error);
- if (error.set) {
+ if (ERROR_SET(&error)) {
// Validation failed, send response with error
if (channel_write(channel,
serialize_response(channel->id,
diff --git a/src/nvim/msgpack_rpc/helpers.c b/src/nvim/msgpack_rpc/helpers.c
index c273343b41..800f5edb85 100644
--- a/src/nvim/msgpack_rpc/helpers.c
+++ b/src/nvim/msgpack_rpc/helpers.c
@@ -475,7 +475,7 @@ Object msgpack_rpc_handle_missing_method(uint64_t channel_id,
Array args,
Error *error)
{
- _api_set_error(error, error->type, "Invalid method name");
+ _api_set_error(error, kErrorTypeException, "Invalid method name");
return NIL;
}
@@ -484,7 +484,7 @@ Object msgpack_rpc_handle_invalid_arguments(uint64_t channel_id,
Array args,
Error *error)
{
- _api_set_error(error, error->type, "Invalid method arguments");
+ _api_set_error(error, kErrorTypeException, "Invalid method arguments");
return NIL;
}
@@ -517,7 +517,7 @@ void msgpack_rpc_serialize_response(uint64_t response_id,
msgpack_pack_int(pac, 1);
msgpack_pack_uint64(pac, response_id);
- if (err->set) {
+ if (ERROR_SET(err)) {
// error represented by a [type, message] array
msgpack_pack_array(pac, 2);
msgpack_rpc_from_integer(err->type, pac);