db/Interface: GetSong() throws exception on error
This commit is contained in:
@@ -41,17 +41,14 @@
|
||||
#include <memory>
|
||||
#include <limits>
|
||||
|
||||
static CommandResult
|
||||
AddUri(Client &client, const LocatedUri &uri, Response &r)
|
||||
static void
|
||||
AddUri(Client &client, const LocatedUri &uri)
|
||||
{
|
||||
Error error;
|
||||
std::unique_ptr<DetachedSong> song(SongLoader(client).LoadSong(uri, error));
|
||||
if (song == nullptr)
|
||||
return print_error(r, error);
|
||||
std::unique_ptr<DetachedSong> song(SongLoader(client).LoadSong(uri));
|
||||
assert(song);
|
||||
|
||||
auto &partition = client.partition;
|
||||
partition.playlist.AppendSong(partition.pc, std::move(*song));
|
||||
return CommandResult::OK;
|
||||
}
|
||||
|
||||
static CommandResult
|
||||
@@ -98,7 +95,8 @@ handle_add(Client &client, Request args, Response &r)
|
||||
|
||||
case LocatedUri::Type::ABSOLUTE:
|
||||
case LocatedUri::Type::PATH:
|
||||
return AddUri(client, located_uri, r);
|
||||
AddUri(client, located_uri);
|
||||
return CommandResult::OK;
|
||||
|
||||
case LocatedUri::Type::RELATIVE:
|
||||
return AddDatabaseSelection(client, located_uri.canonical_uri,
|
||||
|
@@ -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)
|
||||
|
Reference in New Issue
Block a user