PlaylistPrint: throw PlaylistError on error

This commit is contained in:
Max Kellermann 2016-02-28 11:52:39 +01:00
parent 99ded56047
commit 9e2e882157
3 changed files with 15 additions and 19 deletions

View File

@ -46,7 +46,7 @@ playlist_print_uris(Response &r, Partition &partition,
queue_print_uris(r, partition, queue, 0, queue.GetLength()); queue_print_uris(r, partition, queue, 0, queue.GetLength());
} }
bool void
playlist_print_info(Response &r, Partition &partition, playlist_print_info(Response &r, Partition &partition,
const playlist &playlist, const playlist &playlist,
unsigned start, unsigned end) unsigned start, unsigned end)
@ -59,13 +59,12 @@ playlist_print_info(Response &r, Partition &partition,
if (start > end) if (start > end)
/* an invalid "start" offset is fatal */ /* an invalid "start" offset is fatal */
return false; throw PlaylistError::BadRange();
queue_print_info(r, partition, queue, start, end); queue_print_info(r, partition, queue, start, end);
return true;
} }
bool void
playlist_print_id(Response &r, Partition &partition, const playlist &playlist, playlist_print_id(Response &r, Partition &partition, const playlist &playlist,
unsigned id) unsigned id)
{ {
@ -74,10 +73,10 @@ playlist_print_id(Response &r, Partition &partition, const playlist &playlist,
position = playlist.queue.IdToPosition(id); position = playlist.queue.IdToPosition(id);
if (position < 0) if (position < 0)
/* no such song */ /* no such song */
return false; throw PlaylistError::NoSuchSong();
return playlist_print_info(r, partition, playlist_print_info(r, partition,
playlist, position, position + 1); playlist, position, position + 1);
} }
bool bool

View File

@ -41,8 +41,10 @@ playlist_print_uris(Response &r, Partition &partition,
* information about the songs. The "end" offset is decreased * information about the songs. The "end" offset is decreased
* automatically if it is too large; passing UINT_MAX is allowed. * automatically if it is too large; passing UINT_MAX is allowed.
* This function however fails when the start offset is invalid. * 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, playlist_print_info(Response &r, Partition &partition,
const playlist &playlist, const playlist &playlist,
unsigned start, unsigned end); 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. * 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, playlist_print_id(Response &r, Partition &partition,
const playlist &playlist, unsigned id); const playlist &playlist, unsigned id);

View File

@ -251,11 +251,8 @@ handle_playlistinfo(Client &client, Request args, Response &r)
{ {
RangeArg range = args.ParseOptional(0, RangeArg::All()); RangeArg range = args.ParseOptional(0, RangeArg::All());
if (!playlist_print_info(r, client.partition, client.playlist, playlist_print_info(r, client.partition, client.playlist,
range.start, range.end)) range.start, range.end);
return print_playlist_result(r,
PlaylistResult::BAD_RANGE);
return CommandResult::OK; return CommandResult::OK;
} }
@ -264,10 +261,8 @@ handle_playlistid(Client &client, Request args, Response &r)
{ {
if (!args.IsEmpty()) { if (!args.IsEmpty()) {
unsigned id = args.ParseUnsigned(0); unsigned id = args.ParseUnsigned(0);
bool ret = playlist_print_id(r, client.partition, playlist_print_id(r, client.partition,
client.playlist, id); client.playlist, id);
if (!ret)
return print_playlist_result(r, PlaylistResult::NO_SUCH_SONG);
} else { } else {
playlist_print_info(r, client.partition, client.playlist, playlist_print_info(r, client.partition, client.playlist,
0, std::numeric_limits<unsigned>::max()); 0, std::numeric_limits<unsigned>::max());