playlist/Print: throw PlaylistError::NoSuchList instead of returning false

This commit is contained in:
Max Kellermann 2024-05-15 20:17:54 +02:00
parent a5456a89dc
commit 9303764a83
3 changed files with 15 additions and 21 deletions

View File

@ -128,11 +128,9 @@ handle_listplaylist(Client &client, Request args, Response &r)
RangeArg range = args.ParseOptional(1, RangeArg::All()); RangeArg range = args.ParseOptional(1, RangeArg::All());
if (playlist_file_print(r, client.GetPartition(), SongLoader(client), playlist_file_print(r, client.GetPartition(), SongLoader(client),
name, range.start, range.end, false)) name, range.start, range.end, false);
return CommandResult::OK; return CommandResult::OK;
throw PlaylistError::NoSuchList();
} }
CommandResult CommandResult
@ -147,11 +145,9 @@ handle_listplaylistinfo(Client &client, Request args, Response &r)
RangeArg range = args.ParseOptional(1, RangeArg::All()); RangeArg range = args.ParseOptional(1, RangeArg::All());
if (playlist_file_print(r, client.GetPartition(), SongLoader(client), playlist_file_print(r, client.GetPartition(), SongLoader(client),
name, range.start, range.end, true)) name, range.start, range.end, true);
return CommandResult::OK; return CommandResult::OK;
throw PlaylistError::NoSuchList();
} }
CommandResult CommandResult

View File

@ -13,6 +13,7 @@
#include "thread/Mutex.hxx" #include "thread/Mutex.hxx"
#include "Partition.hxx" #include "Partition.hxx"
#include "Instance.hxx" #include "Instance.hxx"
#include "PlaylistError.hxx"
static void static void
playlist_provider_print(Response &r, playlist_provider_print(Response &r,
@ -48,7 +49,7 @@ playlist_provider_print(Response &r,
} }
} }
bool void
playlist_file_print(Response &r, Partition &partition, playlist_file_print(Response &r, Partition &partition,
const SongLoader &loader, const SongLoader &loader,
const LocatedUri &uri, const LocatedUri &uri,
@ -68,9 +69,8 @@ playlist_file_print(Response &r, Partition &partition,
#endif #endif
mutex); mutex);
if (playlist == nullptr) if (playlist == nullptr)
return false; throw PlaylistError::NoSuchList();
playlist_provider_print(r, loader, uri.canonical_uri, *playlist, playlist_provider_print(r, loader, uri.canonical_uri, *playlist,
start_index, end_index, detail); start_index, end_index, detail);
return true;
} }

View File

@ -1,8 +1,7 @@
// SPDX-License-Identifier: GPL-2.0-or-later // SPDX-License-Identifier: GPL-2.0-or-later
// Copyright The Music Player Daemon Project // Copyright The Music Player Daemon Project
#ifndef MPD_PLAYLIST__PRINT_HXX #pragma once
#define MPD_PLAYLIST__PRINT_HXX
class Response; class Response;
class SongLoader; class SongLoader;
@ -11,15 +10,14 @@ struct Partition;
/** /**
* Send the playlist file to the client. * Send the playlist file to the client.
* *
* Throws on error.
*
* @param uri the URI of the playlist file in UTF-8 encoding * @param uri the URI of the playlist file in UTF-8 encoding
* @param detail true if all details should be printed * @param detail true if all details should be printed
* @return true on success, false if the playlist does not exist
*/ */
bool void
playlist_file_print(Response &r, Partition &partition, playlist_file_print(Response &r, Partition &partition,
const SongLoader &loader, const SongLoader &loader,
const LocatedUri &uri, const LocatedUri &uri,
unsigned start_index, unsigned end_index, unsigned start_index, unsigned end_index,
bool detail); bool detail);
#endif