Commit 9e2e8821 authored by Max Kellermann's avatar Max Kellermann

PlaylistPrint: throw PlaylistError on error

parent 99ded560
......@@ -46,7 +46,7 @@ playlist_print_uris(Response &r, Partition &partition,
queue_print_uris(r, partition, queue, 0, queue.GetLength());
}
bool
void
playlist_print_info(Response &r, Partition &partition,
const playlist &playlist,
unsigned start, unsigned end)
......@@ -59,13 +59,12 @@ playlist_print_info(Response &r, Partition &partition,
if (start > end)
/* an invalid "start" offset is fatal */
return false;
throw PlaylistError::BadRange();
queue_print_info(r, partition, queue, start, end);
return true;
}
bool
void
playlist_print_id(Response &r, Partition &partition, const playlist &playlist,
unsigned id)
{
......@@ -74,9 +73,9 @@ playlist_print_id(Response &r, Partition &partition, const playlist &playlist,
position = playlist.queue.IdToPosition(id);
if (position < 0)
/* no such song */
return false;
throw PlaylistError::NoSuchSong();
return playlist_print_info(r, partition,
playlist_print_info(r, partition,
playlist, position, position + 1);
}
......
......@@ -41,8 +41,10 @@ playlist_print_uris(Response &r, Partition &partition,
* information about the songs. The "end" offset is decreased
* automatically if it is too large; passing UINT_MAX is allowed.
* This function however fails when the start offset is invalid.
*
* Throws #PlaylistError if the range is invalid.
*/
bool
void
playlist_print_info(Response &r, Partition &partition,
const playlist &playlist,
unsigned start, unsigned end);
......@@ -50,9 +52,9 @@ playlist_print_info(Response &r, Partition &partition,
/**
* Sends the song with the specified id to the client.
*
* @return true on suite, false if there is no such song
* Throws #PlaylistError if the range is invalid.
*/
bool
void
playlist_print_id(Response &r, Partition &partition,
const playlist &playlist, unsigned id);
......
......@@ -251,11 +251,8 @@ handle_playlistinfo(Client &client, Request args, Response &r)
{
RangeArg range = args.ParseOptional(0, RangeArg::All());
if (!playlist_print_info(r, client.partition, client.playlist,
range.start, range.end))
return print_playlist_result(r,
PlaylistResult::BAD_RANGE);
playlist_print_info(r, client.partition, client.playlist,
range.start, range.end);
return CommandResult::OK;
}
......@@ -264,10 +261,8 @@ handle_playlistid(Client &client, Request args, Response &r)
{
if (!args.IsEmpty()) {
unsigned id = args.ParseUnsigned(0);
bool ret = playlist_print_id(r, client.partition,
playlist_print_id(r, client.partition,
client.playlist, id);
if (!ret)
return print_playlist_result(r, PlaylistResult::NO_SUCH_SONG);
} else {
playlist_print_info(r, client.partition, client.playlist,
0, std::numeric_limits<unsigned>::max());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment