From 53ceeac9ff31a9265802fc0a89562e3ead4ebeae Mon Sep 17 00:00:00 2001 From: fengzero Date: Thu, 16 Jun 2022 10:04:04 +0000 Subject: [PATCH] del unused errorcode --- include/neuron/errcodes.h | 33 ---------------------- plugins/ekuiper/json_rw.c | 2 +- plugins/ekuiper/plugin_ekuiper.c | 4 +-- plugins/mqtt/mqtt.c | 12 ++++---- plugins/restful/http.c | 13 +++++---- plugins/restful/license.c | 4 +-- src/adapter/adapter.c | 8 +++--- src/connection/mqtt_c_client.c | 4 +-- src/persist/persist.c | 48 ++++++++++++++++---------------- 9 files changed, 49 insertions(+), 79 deletions(-) diff --git a/include/neuron/errcodes.h b/include/neuron/errcodes.h index 265578b7..bec49014 100644 --- a/include/neuron/errcodes.h +++ b/include/neuron/errcodes.h @@ -31,39 +31,6 @@ typedef int32_t neu_error; typedef enum { NEU_ERR_SUCCESS = 0, - NEU_ERR_EINTR = -1, - NEU_ERR_ENOMEM = -2, - NEU_ERR_EINVAL = -3, - NEU_ERR_EBUSY = -4, - NEU_ERR_ETIMEDOUT = -5, - NEU_ERR_ECONNREFUSED = -6, - NEU_ERR_ECLOSED = -7, - NEU_ERR_EAGAIN = -8, - NEU_ERR_ENOTSUP = -9, - NEU_ERR_EADDRINUSE = -10, - NEU_ERR_ESTATE = -11, - NEU_ERR_ENOENT = -12, - NEU_ERR_EPROTO = -13, - NEU_ERR_EUNREACHABLE = -14, - NEU_ERR_EADDRINVAL = -15, - NEU_ERR_EPERM = -16, - NEU_ERR_EMSGSIZE = -17, - NEU_ERR_ECONNABORTED = -18, - NEU_ERR_ECONNRESET = -19, - NEU_ERR_ECANCELED = -20, - NEU_ERR_ENOFILES = -21, - NEU_ERR_ENOSPC = -22, - NEU_ERR_EEXIST = -23, - NEU_ERR_EREADONLY = -24, - NEU_ERR_EWRITEONLY = -25, - NEU_ERR_ECRYPTO = -26, - NEU_ERR_EPEERAUTH = -27, - NEU_ERR_ENOARG = -28, - NEU_ERR_EAMBIGUOUS = -29, - NEU_ERR_EBADTYPE = -30, - NEU_ERR_ECONNSHUT = -31, - - NEU_ERR_FAILURE = 1000, // A general error NEU_ERR_EINTERNAL = 1001, // A neuron interanl error NEU_ERR_BODY_IS_WRONG = 1002, NEU_ERR_PARAM_IS_WRONG = 1003, diff --git a/plugins/ekuiper/json_rw.c b/plugins/ekuiper/json_rw.c index 24029496..77624eb3 100644 --- a/plugins/ekuiper/json_rw.c +++ b/plugins/ekuiper/json_rw.c @@ -28,7 +28,7 @@ int wrap_tag_data(neu_json_read_resp_tag_t *json_tag, neu_resp_tag_value_t * tag_value) { if (NULL == json_tag || NULL == tag_value) { - return NEU_ERR_EINVAL; + return -1; } json_tag->name = tag_value->tag; diff --git a/plugins/ekuiper/plugin_ekuiper.c b/plugins/ekuiper/plugin_ekuiper.c index 6455d36b..b775753f 100644 --- a/plugins/ekuiper/plugin_ekuiper.c +++ b/plugins/ekuiper/plugin_ekuiper.c @@ -109,7 +109,7 @@ static int ekuiper_plugin_start(neu_plugin_t *plugin) rv = nng_pair0_open(&plugin->sock); if (rv != 0) { plog_error(plugin, "nng_pair0_open: %s", nng_strerror(rv)); - return NEU_ERR_FAILURE; + return -1; } nng_pipe_notify(plugin->sock, NNG_PIPE_EV_ADD_POST, pipe_add_cb, plugin); @@ -117,7 +117,7 @@ static int ekuiper_plugin_start(neu_plugin_t *plugin) if ((rv = nng_listen(plugin->sock, EKUIPER_PLUGIN_URL, NULL, 0)) != 0) { plog_error(plugin, "nng_listen: %s", nng_strerror(rv)); - return NEU_ERR_FAILURE; + return -1; } nng_recv_aio(plugin->sock, plugin->recv_aio); diff --git a/plugins/mqtt/mqtt.c b/plugins/mqtt/mqtt.c index ee70c15c..7206570d 100644 --- a/plugins/mqtt/mqtt.c +++ b/plugins/mqtt/mqtt.c @@ -315,7 +315,7 @@ static int mqtt_plugin_config(neu_plugin_t *plugin, const char *config) if (NULL == routine) { plugin->routine = NULL; plugin->running = false; - return NEU_ERR_FAILURE; + return NEU_ERR_MQTT_FAILURE; } plugin->routine = routine; @@ -355,7 +355,7 @@ static neu_err_code_e write_response(neu_plugin_t * plugin, neu_resp_error_t *write_data = data; if (!plugin->running) { - return NEU_ERR_FAILURE; + return NEU_ERR_MQTT_FAILURE; } mqtt_routine_t * routine = plugin->routine; @@ -382,7 +382,7 @@ static neu_err_code_e read_response(neu_plugin_t * plugin, neu_resp_read_group_t *read_data = data; if (!plugin->running) { - return NEU_ERR_FAILURE; + return NEU_ERR_MQTT_FAILURE; } mqtt_routine_t * routine = plugin->routine; @@ -409,7 +409,7 @@ static neu_err_code_e trans_data(neu_plugin_t *plugin, void *data) neu_reqresp_trans_data_t *trans_data = data; if (!plugin->running) { - return NEU_ERR_FAILURE; + return NEU_ERR_MQTT_FAILURE; } mqtt_routine_t * routine = plugin->routine; @@ -418,7 +418,7 @@ static neu_err_code_e trans_data(neu_plugin_t *plugin, void *data) char * json = command_read_periodic_response(trans_data, routine->option.format); if (NULL == json) { - return NEU_ERR_FAILURE; + return NEU_ERR_MQTT_FAILURE; } const char * topic = pair->topic_response; @@ -461,7 +461,7 @@ static int mqtt_plugin_request(neu_plugin_t *plugin, neu_reqresp_head_t *head, break; } default: - error = NEU_ERR_FAILURE; + error = NEU_ERR_MQTT_FAILURE; break; } diff --git a/plugins/restful/http.c b/plugins/restful/http.c index 00601b4f..e5abe9c1 100644 --- a/plugins/restful/http.c +++ b/plugins/restful/http.c @@ -195,17 +195,17 @@ int http_get_param_uintmax(nng_aio *aio, const char *name, uintmax_t *param) uintmax_t result = 0; if (tmp == NULL) { - return NEU_ERR_ENOENT; + return -1; } if (0 == len) { - return NEU_ERR_EINVAL; + return -1; } result = strtoumax(tmp, &end, 10); if ((result == UINTMAX_MAX && errno == ERANGE) || result > UINTMAX_MAX || tmp + len != end) { - return NEU_ERR_EINVAL; + return -1; } *param = result; @@ -223,7 +223,7 @@ int http_get_param_uint64(nng_aio *aio, const char *name, uint64_t *param) } if (val > UINT64_MAX) { - return NEU_ERR_EINVAL; + return -1; } *param = (uint64_t) val; @@ -240,7 +240,7 @@ int http_get_param_uint32(nng_aio *aio, const char *name, uint32_t *param) } if (val > UINT32_MAX) { - return NEU_ERR_EINVAL; + return -1; } *param = (uint32_t) val; @@ -282,6 +282,7 @@ int http_response(nng_aio *aio, neu_err_code_e code, char *content) case NEU_ERR_LICENSE_MAX_NODES: case NEU_ERR_LICENSE_MAX_TAGS: case NEU_ERR_GROUP_ALREADY_SUBSCRIBED: + case NEU_ERR_PLUGIN_TAG_TYPE_MISMATCH: status = NNG_HTTP_STATUS_OK; break; case NEU_ERR_EINTERNAL: @@ -305,6 +306,8 @@ int http_response(nng_aio *aio, neu_err_code_e code, char *content) case NEU_ERR_LICENSE_INVALID: case NEU_ERR_GROUP_PARAMETER_INVALID: case NEU_ERR_LIBRARY_SYSTEM_NOT_ALLOW_DEL: + case NEU_ERR_LIBRARY_FAILED_TO_OPEN: + case NEU_ERR_LIBRARY_MODULE_INVALID: status = NNG_HTTP_STATUS_BAD_REQUEST; break; case NEU_ERR_LIBRARY_NOT_FOUND: diff --git a/plugins/restful/license.c b/plugins/restful/license.c index fca34d97..f212eeed 100644 --- a/plugins/restful/license.c +++ b/plugins/restful/license.c @@ -387,7 +387,7 @@ void license_free(license_t *license) int license_read(license_t *license, const char *fname) { if (NULL == license || NULL == fname) { - return NEU_ERR_EINVAL; + return -1; } license_t lic; @@ -395,7 +395,7 @@ int license_read(license_t *license, const char *fname) lic.fname_ = strdup(fname); if (NULL == lic.fname_) { - return NEU_ERR_ENOMEM; + return -1; } int rv = extract_license(fname, root_cert_pub_key, &lic); diff --git a/src/adapter/adapter.c b/src/adapter/adapter.c index 9af1c85a..006e50c3 100644 --- a/src/adapter/adapter.c +++ b/src/adapter/adapter.c @@ -92,7 +92,7 @@ static int persister_singleton_load_setting(neu_adapter_t *adapter, neu_persister_load_adapter_setting(persister, adapter_name, &setting); if (0 != rv) { const char *fail_or_ignore = "fail"; - if (NEU_ERR_ENOENT == rv) { + if (rv != 0) { // ignore this error, no setting ever set rv = 0; fail_or_ignore = "ignore"; @@ -121,7 +121,7 @@ static int persister_singleton_load_datatags(neu_adapter_t *adapter, int rv = neu_persister_load_datatags(persister, driver, group, &tags); if (0 != rv) { const char *fail_or_ignore = "fail"; - if (NEU_ERR_ENOENT == rv) { + if (rv != 0) { // ignore no datatags rv = 0; fail_or_ignore = "ignore"; @@ -153,7 +153,7 @@ static int persister_singleton_load_grp_and_tags(neu_adapter_t *adapter, &group_config_infos); if (0 != rv) { const char *fail_or_ignore = "fail"; - if (NEU_ERR_ENOENT == rv) { + if (rv != 0) { // ignore no group configs rv = 0; fail_or_ignore = "ignore"; @@ -190,7 +190,7 @@ static int persister_singleton_load_subscriptions(neu_adapter_t *adapter, rv = neu_persister_load_subscriptions(persister, adapter_name, &sub_infos); if (0 != rv) { const char *fail_or_ignore = "fail"; - if (NEU_ERR_ENOENT == rv) { + if (rv != 0) { // ignore no subscriptions rv = 0; fail_or_ignore = "ignore"; diff --git a/src/connection/mqtt_c_client.c b/src/connection/mqtt_c_client.c index 8ce2e254..d6fe65d5 100644 --- a/src/connection/mqtt_c_client.c +++ b/src/connection/mqtt_c_client.c @@ -599,13 +599,13 @@ static neu_err_code_e client_init(mqtt_c_client_t *client) if (0 == strcmp(option->connection, "ssl://")) { ssl_ctx_init(&client->state); if (NULL == client->state.ssl_ctx) { - return NEU_ERR_FAILURE; + return NEU_ERR_MQTT_FAILURE; } } bio_init(&client->state); if (NULL == client->state.sock_fd) { - return NEU_ERR_FAILURE; + return NEU_ERR_MQTT_FAILURE; } return NEU_ERR_SUCCESS; diff --git a/src/persist/persist.c b/src/persist/persist.c index 84793a3f..3a330ecc 100644 --- a/src/persist/persist.c +++ b/src/persist/persist.c @@ -254,7 +254,7 @@ static int file_tree_walk_(char *path_buf, size_t len, size_t size, // if not possible to read the directory for this user if ((dirp = opendir(path_buf)) == NULL) { - rv = (ENOENT == errno) ? NEU_ERR_ENOENT : NEU_ERR_FAILURE; + rv = -1; return rv; } @@ -349,16 +349,16 @@ static inline int ensure_file_exist(const char *name, { int fd = open(name, O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR); if (-1 == fd) { - return NEU_ERR_FAILURE; + return -1; } struct stat statbuf; if (-1 == fstat(fd, &statbuf)) { - return NEU_ERR_FAILURE; + return -1; } if (0 == statbuf.st_size) { ssize_t size = strlen(default_content); if (size != write(fd, default_content, size)) { - return NEU_ERR_FAILURE; + return -1; } } return 0; @@ -369,13 +369,13 @@ static int write_file_string(const char *fn, const char *s) char tmp[PATH_MAX_SIZE] = { 0 }; if (sizeof(tmp) == snprintf(tmp, sizeof(tmp), "%s.tmp", fn)) { nlog_error("persister too long file name:%s", fn); - return NEU_ERR_FAILURE; + return -1; } FILE *f = fopen(tmp, "w+"); if (NULL == f) { nlog_error("persister failed to open file:%s", fn); - return NEU_ERR_FAILURE; + return -1; } // write to a temporary file first @@ -383,7 +383,7 @@ static int write_file_string(const char *fn, const char *s) if (((size_t) n) != fwrite(s, 1, n, f)) { nlog_error("persister failed to write file:%s", fn); fclose(f); - return NEU_ERR_FAILURE; + return -1; } fclose(f); @@ -393,7 +393,7 @@ static int write_file_string(const char *fn, const char *s) // rename the temporary file to the destination file if (0 != rename(tmp, fn)) { nlog_error("persister failed rename %s to %s", tmp, fn); - return NEU_ERR_FAILURE; + return -1; } return 0; @@ -405,7 +405,7 @@ static int read_file_string(const char *fn, char **out) int rv = 0; int fd = open(fn, O_RDONLY); if (-1 == fd) { - rv = (ENOENT == errno) ? NEU_ERR_ENOENT : NEU_ERR_FAILURE; + rv = -1; goto error_open; } @@ -418,7 +418,7 @@ static int read_file_string(const char *fn, char **out) char *buf = malloc(fsize + 1); if (NULL == buf) { - rv = NEU_ERR_ENOMEM; + rv = -1; goto error_buf; } @@ -430,7 +430,7 @@ static int read_file_string(const char *fn, char **out) } else if (n < fsize && EINTR == errno) { continue; } else { - rv = NEU_ERR_FAILURE; + rv = -1; goto error_read; } } @@ -758,7 +758,7 @@ int neu_persister_delete_adapter(neu_persister_t *persister, int n = persister_adapter_dir(path, sizeof(path), persister, adapter_name); if (sizeof(path) == n) { nlog_error("persister path too long: %s", path); - return NEU_ERR_FAILURE; + return -1; } rmdir_recursive(path); return 0; @@ -771,18 +771,18 @@ int neu_persister_update_adapter(neu_persister_t *persister, int n = persister_adapter_dir(path, sizeof(path), persister, adapter_name); if (sizeof(path) == n) { nlog_error("persister path too long: %s", path); - return NEU_ERR_FAILURE; + return -1; } char new_path[PATH_MAX_SIZE] = { 0 }; n = persister_adapter_dir(new_path, sizeof(new_path), persister, new_name); if (sizeof(new_path) == n) { nlog_error("persister new path too long: %s", new_path); - return NEU_ERR_FAILURE; + return -1; } if (0 != rename(path, new_path)) { - return NEU_ERR_FAILURE; + return -1; } return 0; @@ -858,19 +858,19 @@ int neu_persister_store_datatags(neu_persister_t *persister, adapter_name, group_config_name); if (sizeof(path) == n) { nlog_error("path too long: %s", path); - return NEU_ERR_FAILURE; + return -1; } int rv = create_dir_recursive(path); if (0 != rv) { nlog_error("fail to create dir: %s", path); - return NEU_ERR_FAILURE; + return -1; } n = path_cat(path, n, sizeof(path), "datatags.json"); if (sizeof(path) == n) { nlog_error("path too long: %s", path); - return NEU_ERR_FAILURE; + return -1; } neu_json_datatag_req_t datatags_resp = { 0 }; @@ -912,13 +912,13 @@ int neu_persister_load_datatags(neu_persister_t *persister, adapter_name, group_config_name); if (sizeof(path) == n) { nlog_error("path too long: %s", path); - return NEU_ERR_FAILURE; + return -1; } n = path_cat(path, n, sizeof(path), "datatags.json"); if (sizeof(path) == n) { nlog_error("path too long: %s", path); - return NEU_ERR_FAILURE; + return -1; } char *json_str = NULL; @@ -961,7 +961,7 @@ int neu_persister_store_subscriptions(neu_persister_t *persister, int n = persister_adapter_dir(path, sizeof(path), persister, adapter_name); if (sizeof(path) == n) { nlog_error("path too long: %s", path); - return NEU_ERR_FAILURE; + return -1; } int rv = create_dir(path); @@ -973,7 +973,7 @@ int neu_persister_store_subscriptions(neu_persister_t *persister, n = path_cat(path, n, sizeof(path), "subscriptions.json"); if (sizeof(path) == n) { nlog_error("path too long: %s", path); - return NEU_ERR_FAILURE; + return -1; } neu_json_subscriptions_req_t subs_resp = { 0 }; @@ -1012,13 +1012,13 @@ int neu_persister_load_subscriptions(neu_persister_t *persister, int n = persister_adapter_dir(path, sizeof(path), persister, adapter_name); if (sizeof(path) == n) { nlog_error("path too long: %s", path); - return NEU_ERR_FAILURE; + return -1; } n = path_cat(path, n, sizeof(path), "subscriptions.json"); if (sizeof(path) == n) { nlog_error("path too long: %s", path); - return NEU_ERR_FAILURE; + return -1; } char *json_str = NULL;