db/Interface: GetSong() throws exception on error

This commit is contained in:
Max Kellermann
2016-03-19 00:13:57 +01:00
parent 7ad7caa2ae
commit 2fd5182608
15 changed files with 43 additions and 67 deletions

View File

@@ -62,9 +62,7 @@ handle_sticker_song(Response &r, Partition &partition, Request args)
/* get song song_id key */
if (args.size == 4 && StringIsEqual(cmd, "get")) {
const LightSong *song = db->GetSong(args[2], error);
if (song == nullptr)
return print_error(r, error);
const LightSong *song = db->GetSong(args[2]);
const auto value = sticker_song_get_value(*song, args[3],
error);
@@ -82,9 +80,8 @@ handle_sticker_song(Response &r, Partition &partition, Request args)
return CommandResult::OK;
/* list song song_id */
} else if (args.size == 3 && StringIsEqual(cmd, "list")) {
const LightSong *song = db->GetSong(args[2], error);
if (song == nullptr)
return print_error(r, error);
const LightSong *song = db->GetSong(args[2]);
assert(song != nullptr);
Sticker *sticker = sticker_song_get(*song, error);
db->ReturnSong(song);
@@ -97,9 +94,8 @@ handle_sticker_song(Response &r, Partition &partition, Request args)
return CommandResult::OK;
/* set song song_id id key */
} else if (args.size == 5 && StringIsEqual(cmd, "set")) {
const LightSong *song = db->GetSong(args[2], error);
if (song == nullptr)
return print_error(r, error);
const LightSong *song = db->GetSong(args[2]);
assert(song != nullptr);
bool ret = sticker_song_set_value(*song, args[3], args[4],
error);
@@ -117,9 +113,8 @@ handle_sticker_song(Response &r, Partition &partition, Request args)
/* delete song song_id [key] */
} else if ((args.size == 3 || args.size == 4) &&
StringIsEqual(cmd, "delete")) {
const LightSong *song = db->GetSong(args[2], error);
if (song == nullptr)
return print_error(r, error);
const LightSong *song = db->GetSong(args[2]);
assert(song != nullptr);
bool ret = args.size == 3
? sticker_song_delete(*song, error)