diff options
author | Přemysl Janouch <p.janouch@gmail.com> | 2014-07-15 22:54:39 +0200 |
---|---|---|
committer | Přemysl Janouch <p.janouch@gmail.com> | 2014-07-16 00:53:59 +0200 |
commit | 2921eed702d994352c5afccc31e32bd3f1682b6b (patch) | |
tree | 044ef2300088f723d627ab529d7c052a84f74b48 /src/zyklonb.c | |
parent | a2a979ea2e7ded82cbe4d4cab5da6e613d74a9d0 (diff) | |
download | xK-2921eed702d994352c5afccc31e32bd3f1682b6b.tar.gz xK-2921eed702d994352c5afccc31e32bd3f1682b6b.tar.xz xK-2921eed702d994352c5afccc31e32bd3f1682b6b.zip |
Rip out error codes
As it turns out, they're rather annoying to maintain, and we don't even need
them. They also clutter the code unnecessarily in their current form.
If it ever comes to having to have them, let's make another version of
error_set(), maybe error_set_with_code(), that makes it possible to also set
an integer within `struct error'.
The only problem with the above solution is when we aggregate errors from
multiple functions (be it by calling one after another, or through nesting of
functions that may return an error).
But let's care about that when the time comes for it.
Diffstat (limited to 'src/zyklonb.c')
-rw-r--r-- | src/zyklonb.c | 50 |
1 files changed, 12 insertions, 38 deletions
diff --git a/src/zyklonb.c b/src/zyklonb.c index de4e3ac..906df7e 100644 --- a/src/zyklonb.c +++ b/src/zyklonb.c @@ -106,15 +106,6 @@ plugin_data_free (struct plugin_data *self) str_free (&self->queued_output); } -static size_t connect_error_domain_tag; -#define CONNECT_ERROR (error_resolve_domain (&connect_error_domain_tag)) - -enum -{ - CONNECT_ERROR_INVALID_CONFIGURATION, - CONNECT_ERROR_FAILED -}; - struct bot_context { struct str_map config; ///< User configuration @@ -306,8 +297,7 @@ error_ssl_2: error_ssl_1: // XXX: these error strings are really nasty; also there could be // multiple errors on the OpenSSL stack. - error_set (e, CONNECT_ERROR, CONNECT_ERROR_FAILED, - "%s: %s", "could not initialize SSL", + error_set (e, "%s: %s", "could not initialize SSL", ERR_error_string (ERR_get_error (), NULL)); return false; } @@ -325,7 +315,7 @@ irc_establish_connection (struct bot_context *ctx, int err = getaddrinfo (host, port, &gai_hints, &gai_result); if (err) { - error_set (e, CONNECT_ERROR, CONNECT_ERROR_FAILED, "%s: %s: %s", + error_set (e, "%s: %s: %s", "connection failed", "getaddrinfo", gai_strerror (err)); return false; } @@ -367,7 +357,7 @@ irc_establish_connection (struct bot_context *ctx, if (!gai_iter) { - error_set (e, CONNECT_ERROR, CONNECT_ERROR_FAILED, "connection failed"); + error_set (e, "connection failed"); return false; } @@ -633,16 +623,6 @@ setup_recovery_handler (struct bot_context *ctx) /// The name of the special IRC command for interprocess communication static const char *plugin_ipc_command = "ZYKLONB"; -static size_t plugin_error_domain_tag; -#define PLUGIN_ERROR (error_resolve_domain (&plugin_error_domain_tag)) - -enum -{ - PLUGIN_ERROR_ALREADY_LOADED, - PLUGIN_ERROR_NOT_LOADED, - PLUGIN_ERROR_LOADING_FAILED -}; - static struct plugin_data * plugin_find_by_pid (struct bot_context *ctx, pid_t pid) { @@ -923,29 +903,26 @@ plugin_load (struct bot_context *ctx, const char *name, struct error **e) const char *plugin_dir = str_map_find (&ctx->config, "plugin_dir"); if (!plugin_dir) { - error_set (e, PLUGIN_ERROR, PLUGIN_ERROR_LOADING_FAILED, - "plugin directory not set"); + error_set (e, "plugin directory not set"); return false; } if (!is_valid_plugin_name (name)) { - error_set (e, PLUGIN_ERROR, PLUGIN_ERROR_LOADING_FAILED, - "invalid plugin name"); + error_set (e, "invalid plugin name"); return false; } if (str_map_find (&ctx->plugins_by_name, name)) { - error_set (e, PLUGIN_ERROR, PLUGIN_ERROR_ALREADY_LOADED, - "the plugin has already been loaded"); + error_set (e, "the plugin has already been loaded"); return false; } int stdin_pipe[2]; if (pipe (stdin_pipe) == -1) { - error_set (e, PLUGIN_ERROR, PLUGIN_ERROR_LOADING_FAILED, "%s: %s: %s", + error_set (e, "%s: %s: %s", "failed to load the plugin", "pipe", strerror (errno)); goto fail_1; } @@ -953,7 +930,7 @@ plugin_load (struct bot_context *ctx, const char *name, struct error **e) int stdout_pipe[2]; if (pipe (stdout_pipe) == -1) { - error_set (e, PLUGIN_ERROR, PLUGIN_ERROR_LOADING_FAILED, "%s: %s: %s", + error_set (e, "%s: %s: %s", "failed to load the plugin", "pipe", strerror (errno)); goto fail_2; } @@ -964,7 +941,7 @@ plugin_load (struct bot_context *ctx, const char *name, struct error **e) pid_t pid = fork (); if (pid == -1) { - error_set (e, PLUGIN_ERROR, PLUGIN_ERROR_LOADING_FAILED, "%s: %s: %s", + error_set (e, "%s: %s: %s", "failed to load the plugin", "fork", strerror (errno)); goto fail_3; } @@ -1034,8 +1011,7 @@ plugin_unload (struct bot_context *ctx, const char *name, struct error **e) if (!plugin) { - error_set (e, PLUGIN_ERROR, PLUGIN_ERROR_NOT_LOADED, - "no such plugin is loaded"); + error_set (e, "no such plugin is loaded"); return false; } @@ -1551,16 +1527,14 @@ irc_connect (struct bot_context *ctx, struct error **e) // do we tell our caller that he should not try to reconnect? if (!irc_host) { - error_set (e, CONNECT_ERROR, CONNECT_ERROR_INVALID_CONFIGURATION, - "no hostname specified in configuration"); + error_set (e, "no hostname specified in configuration"); return false; } bool use_ssl; if (!set_boolean_if_valid (&use_ssl, ssl_use_str)) { - error_set (e, CONNECT_ERROR, CONNECT_ERROR_INVALID_CONFIGURATION, - "invalid configuration value for `%s'", "use_ssl"); + error_set (e, "invalid configuration value for `%s'", "use_ssl"); return false; } |