From 204a1de3fd575deadda595b39799b9b9f6e7564e Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 12 Dec 2014 14:13:14 +0100 Subject: sticker/Database: use the Error library --- src/command/StickerCommands.cxx | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) (limited to 'src/command/StickerCommands.cxx') diff --git a/src/command/StickerCommands.cxx b/src/command/StickerCommands.cxx index 088a07a79..f2fad86cc 100644 --- a/src/command/StickerCommands.cxx +++ b/src/command/StickerCommands.cxx @@ -67,9 +67,13 @@ handle_sticker_song(Client &client, ConstBuffer args) if (song == nullptr) return print_error(client, error); - const auto value = sticker_song_get_value(*song, args[3]); + const auto value = sticker_song_get_value(*song, args[3], + error); db->ReturnSong(song); if (value.empty()) { + if (error.IsDefined()) + return print_error(client, error); + command_error(client, ACK_ERROR_NO_EXIST, "no such sticker"); return CommandResult::ERROR; @@ -84,12 +88,13 @@ handle_sticker_song(Client &client, ConstBuffer args) if (song == nullptr) return print_error(client, error); - sticker *sticker = sticker_song_get(*song); + sticker *sticker = sticker_song_get(*song, error); db->ReturnSong(song); if (sticker) { sticker_print(client, *sticker); sticker_free(sticker); - } + } else if (error.IsDefined()) + return print_error(client, error); return CommandResult::OK; /* set song song_id id key */ @@ -98,9 +103,13 @@ handle_sticker_song(Client &client, ConstBuffer args) if (song == nullptr) return print_error(client, error); - bool ret = sticker_song_set_value(*song, args[3], args[4]); + bool ret = sticker_song_set_value(*song, args[3], args[4], + error); db->ReturnSong(song); if (!ret) { + if (error.IsDefined()) + return print_error(client, error); + command_error(client, ACK_ERROR_SYSTEM, "failed to set sticker value"); return CommandResult::ERROR; @@ -115,10 +124,13 @@ handle_sticker_song(Client &client, ConstBuffer args) return print_error(client, error); bool ret = args.size == 3 - ? sticker_song_delete(*song) - : sticker_song_delete_value(*song, args[3]); + ? sticker_song_delete(*song, error) + : sticker_song_delete_value(*song, args[3], error); db->ReturnSong(song); if (!ret) { + if (error.IsDefined()) + return print_error(client, error); + command_error(client, ACK_ERROR_SYSTEM, "no such sticker"); return CommandResult::ERROR; @@ -138,8 +150,12 @@ handle_sticker_song(Client &client, ConstBuffer args) }; success = sticker_song_find(*db, base_uri, data.name, - sticker_song_find_print_cb, &data); + sticker_song_find_print_cb, &data, + error); if (!success) { + if (error.IsDefined()) + return print_error(client, error); + command_error(client, ACK_ERROR_SYSTEM, "failed to set search sticker database"); return CommandResult::ERROR; -- cgit v1.2.3