aboutsummaryrefslogtreecommitdiffstats
path: root/src/CommandError.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-08-10 18:02:44 +0200
committerMax Kellermann <max@duempel.org>2013-09-04 18:14:22 +0200
commit29030b54c98b0aee65fbc10ebf7ba36bed98c02c (patch)
tree79766830b55ebca38ddbce84d8d548227eedb69e /src/CommandError.cxx
parentc9fcc7f14860777458153eb2d13c773ccfa1daa2 (diff)
downloadmpd-29030b54c98b0aee65fbc10ebf7ba36bed98c02c.tar.gz
mpd-29030b54c98b0aee65fbc10ebf7ba36bed98c02c.tar.xz
mpd-29030b54c98b0aee65fbc10ebf7ba36bed98c02c.zip
util/Error: new error passing library
Replaces GLib's GError.
Diffstat (limited to 'src/CommandError.cxx')
-rw-r--r--src/CommandError.cxx44
1 files changed, 17 insertions, 27 deletions
diff --git a/src/CommandError.cxx b/src/CommandError.cxx
index 7a33761ae..c9b6c2deb 100644
--- a/src/CommandError.cxx
+++ b/src/CommandError.cxx
@@ -20,8 +20,10 @@
#include "config.h"
#include "CommandError.hxx"
#include "DatabaseError.hxx"
-#include "io_error.h"
#include "protocol/Result.hxx"
+#include "util/Error.hxx"
+
+#include <glib.h>
#include <assert.h>
#include <errno.h>
@@ -85,50 +87,38 @@ print_playlist_result(Client *client, enum playlist_result result)
return COMMAND_RETURN_ERROR;
}
-/**
- * Send the GError to the client and free the GError.
- */
enum command_return
-print_error(Client *client, GError *error)
+print_error(Client *client, const Error &error)
{
assert(client != NULL);
- assert(error != NULL);
+ assert(error.IsDefined());
- g_warning("%s", error->message);
+ g_warning("%s", error.GetMessage());
- if (error->domain == playlist_quark()) {
- enum playlist_result result = (playlist_result)error->code;
- g_error_free(error);
- return print_playlist_result(client, result);
- } else if (error->domain == ack_quark()) {
- command_error(client, (ack)error->code, "%s", error->message);
- g_error_free(error);
+ if (error.IsDomain(playlist_domain)) {
+ return print_playlist_result(client,
+ playlist_result(error.GetCode()));
+ } else if (error.IsDomain(ack_domain)) {
+ command_error(client, (ack)error.GetCode(),
+ "%s", error.GetMessage());
return COMMAND_RETURN_ERROR;
- } else if (error->domain == db_quark()) {
- switch ((enum db_error)error->code) {
+ } else if (error.IsDomain(db_domain)) {
+ switch ((enum db_error)error.GetCode()) {
case DB_DISABLED:
command_error(client, ACK_ERROR_NO_EXIST, "%s",
- error->message);
- g_error_free(error);
+ error.GetMessage());
return COMMAND_RETURN_ERROR;
case DB_NOT_FOUND:
- g_error_free(error);
command_error(client, ACK_ERROR_NO_EXIST, "Not found");
return COMMAND_RETURN_ERROR;
}
- } else if (error->domain == errno_quark()) {
+ } else if (error.IsDomain(errno_domain)) {
command_error(client, ACK_ERROR_SYSTEM, "%s",
- g_strerror(error->code));
- g_error_free(error);
- return COMMAND_RETURN_ERROR;
- } else if (error->domain == g_file_error_quark()) {
- command_error(client, ACK_ERROR_SYSTEM, "%s", error->message);
- g_error_free(error);
+ g_strerror(error.GetCode()));
return COMMAND_RETURN_ERROR;
}
- g_error_free(error);
command_error(client, ACK_ERROR_UNKNOWN, "error");
return COMMAND_RETURN_ERROR;
}