mirror of
				https://github.com/neovim/neovim.git
				synced 2025-10-26 12:27:24 +00:00 
			
		
		
		
	api/internal: Remove set field from Error type.
				
					
				
			This commit is contained in:
		| @@ -225,7 +225,7 @@ for i = 1, #functions do | ||||
|     end | ||||
|     output:write('\n') | ||||
|     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  }\n') | ||||
|  | ||||
| @@ -250,7 +250,7 @@ for i = 1, #functions do | ||||
|           output:write('\n    '..converted..' = (handle_T)args.items['..(j - 1)..'].data.integer;') | ||||
|         end | ||||
|         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  }\n') | ||||
|       else | ||||
| @@ -290,7 +290,7 @@ for i = 1, #functions do | ||||
|         output:write('error);\n') | ||||
|       end | ||||
|       -- 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  }\n') | ||||
|     else | ||||
|   | ||||
| @@ -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); | ||||
|     } | ||||
|   | ||||
| @@ -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; | ||||
|   | ||||
| @@ -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; | ||||
| } | ||||
|   | ||||
| @@ -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(); | ||||
|   } | ||||
| } | ||||
|   | ||||
| @@ -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)); | ||||
|   | ||||
| @@ -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; | ||||
|   } | ||||
|   | ||||
| @@ -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, | ||||
|   | ||||
| @@ -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); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Justin M. Keyes
					Justin M. Keyes