aboutsummaryrefslogtreecommitdiffstats
path: root/src/PlaylistCommands.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/PlaylistCommands.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/PlaylistCommands.cxx')
-rw-r--r--src/PlaylistCommands.cxx60
1 files changed, 32 insertions, 28 deletions
diff --git a/src/PlaylistCommands.cxx b/src/PlaylistCommands.cxx
index faa8b72bb..785267c1d 100644
--- a/src/PlaylistCommands.cxx
+++ b/src/PlaylistCommands.cxx
@@ -33,6 +33,7 @@
#include "ls.hxx"
#include "Playlist.hxx"
#include "util/UriUtil.hxx"
+#include "util/Error.hxx"
#include <assert.h>
#include <stdlib.h>
@@ -64,7 +65,7 @@ handle_load(Client *client, int argc, char *argv[])
if (argc < 3) {
start_index = 0;
- end_index = G_MAXUINT;
+ end_index = unsigned(-1);
} else if (!check_range(client, &start_index, &end_index, argv[2]))
return COMMAND_RETURN_ERROR;
@@ -77,19 +78,22 @@ handle_load(Client *client, int argc, char *argv[])
if (result != PLAYLIST_RESULT_NO_SUCH_LIST)
return print_playlist_result(client, result);
- GError *error = NULL;
+ Error error;
if (playlist_load_spl(&client->playlist, client->player_control,
argv[1], start_index, end_index,
- &error))
+ error))
return COMMAND_RETURN_OK;
- if (error->domain == playlist_quark() &&
- error->code == PLAYLIST_RESULT_BAD_NAME)
+ if (error.IsDomain(playlist_domain) &&
+ error.GetCode() == PLAYLIST_RESULT_BAD_NAME) {
/* the message for BAD_NAME is confusing when the
client wants to load a playlist file from the music
- directory; patch the GError object to show "no such
+ directory; patch the Error object to show "no such
playlist" instead */
- error->code = PLAYLIST_RESULT_NO_SUCH_LIST;
+ Error error2(playlist_domain, PLAYLIST_RESULT_NO_SUCH_LIST,
+ error.GetMessage());
+ error = std::move(error2);
+ }
return print_error(client, error);
}
@@ -100,8 +104,8 @@ handle_listplaylist(Client *client, gcc_unused int argc, char *argv[])
if (playlist_file_print(client, argv[1], false))
return COMMAND_RETURN_OK;
- GError *error = NULL;
- return spl_print(client, argv[1], false, &error)
+ Error error;
+ return spl_print(client, argv[1], false, error)
? COMMAND_RETURN_OK
: print_error(client, error);
}
@@ -113,8 +117,8 @@ handle_listplaylistinfo(Client *client,
if (playlist_file_print(client, argv[1], true))
return COMMAND_RETURN_OK;
- GError *error = NULL;
- return spl_print(client, argv[1], true, &error)
+ Error error;
+ return spl_print(client, argv[1], true, error)
? COMMAND_RETURN_OK
: print_error(client, error);
}
@@ -122,8 +126,8 @@ handle_listplaylistinfo(Client *client,
enum command_return
handle_rm(Client *client, gcc_unused int argc, char *argv[])
{
- GError *error = NULL;
- return spl_delete(argv[1], &error)
+ Error error;
+ return spl_delete(argv[1], error)
? COMMAND_RETURN_OK
: print_error(client, error);
}
@@ -131,8 +135,8 @@ handle_rm(Client *client, gcc_unused int argc, char *argv[])
enum command_return
handle_rename(Client *client, gcc_unused int argc, char *argv[])
{
- GError *error = NULL;
- return spl_rename(argv[1], argv[2], &error)
+ Error error;
+ return spl_rename(argv[1], argv[2], error)
? COMMAND_RETURN_OK
: print_error(client, error);
}
@@ -146,8 +150,8 @@ handle_playlistdelete(Client *client,
if (!check_unsigned(client, &from, argv[2]))
return COMMAND_RETURN_ERROR;
- GError *error = NULL;
- return spl_remove_index(playlist, from, &error)
+ Error error;
+ return spl_remove_index(playlist, from, error)
? COMMAND_RETURN_OK
: print_error(client, error);
}
@@ -163,8 +167,8 @@ handle_playlistmove(Client *client, gcc_unused int argc, char *argv[])
if (!check_unsigned(client, &to, argv[3]))
return COMMAND_RETURN_ERROR;
- GError *error = NULL;
- return spl_move_index(playlist, from, to, &error)
+ Error error;
+ return spl_move_index(playlist, from, to, error)
? COMMAND_RETURN_OK
: print_error(client, error);
}
@@ -172,8 +176,8 @@ handle_playlistmove(Client *client, gcc_unused int argc, char *argv[])
enum command_return
handle_playlistclear(Client *client, gcc_unused int argc, char *argv[])
{
- GError *error = NULL;
- return spl_clear(argv[1], &error)
+ Error error;
+ return spl_clear(argv[1], error)
? COMMAND_RETURN_OK
: print_error(client, error);
}
@@ -185,7 +189,7 @@ handle_playlistadd(Client *client, gcc_unused int argc, char *argv[])
char *uri = argv[2];
bool success;
- GError *error = NULL;
+ Error error;
if (uri_has_scheme(uri)) {
if (!uri_supported_scheme(uri)) {
command_error(client, ACK_ERROR_NO_EXIST,
@@ -193,12 +197,12 @@ handle_playlistadd(Client *client, gcc_unused int argc, char *argv[])
return COMMAND_RETURN_ERROR;
}
- success = spl_append_uri(uri, playlist, &error);
+ success = spl_append_uri(uri, playlist, error);
} else
success = search_add_to_playlist(uri, playlist, nullptr,
- &error);
+ error);
- if (!success && error == NULL) {
+ if (!success && !error.IsDefined()) {
command_error(client, ACK_ERROR_NO_EXIST,
"directory or file not found");
return COMMAND_RETURN_ERROR;
@@ -211,9 +215,9 @@ enum command_return
handle_listplaylists(Client *client,
gcc_unused int argc, gcc_unused char *argv[])
{
- GError *error = NULL;
- const auto list = ListPlaylistFiles(&error);
- if (list.empty() && error != NULL)
+ Error error;
+ const auto list = ListPlaylistFiles(error);
+ if (list.empty() && error.IsDefined())
return print_error(client, error);
print_spl_list(client, list);