From 9303764a835967ee14c86cb7c3bdcc849fff3a49 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 15 May 2024 20:17:54 +0200 Subject: [PATCH] playlist/Print: throw PlaylistError::NoSuchList instead of returning false --- src/command/PlaylistCommands.cxx | 16 ++++++---------- src/playlist/Print.cxx | 6 +++--- src/playlist/Print.hxx | 14 ++++++-------- 3 files changed, 15 insertions(+), 21 deletions(-) diff --git a/src/command/PlaylistCommands.cxx b/src/command/PlaylistCommands.cxx index b6746a68e..ea69548cd 100644 --- a/src/command/PlaylistCommands.cxx +++ b/src/command/PlaylistCommands.cxx @@ -128,11 +128,9 @@ handle_listplaylist(Client &client, Request args, Response &r) RangeArg range = args.ParseOptional(1, RangeArg::All()); - if (playlist_file_print(r, client.GetPartition(), SongLoader(client), - name, range.start, range.end, false)) - return CommandResult::OK; - - throw PlaylistError::NoSuchList(); + playlist_file_print(r, client.GetPartition(), SongLoader(client), + name, range.start, range.end, false); + return CommandResult::OK; } CommandResult @@ -147,11 +145,9 @@ handle_listplaylistinfo(Client &client, Request args, Response &r) RangeArg range = args.ParseOptional(1, RangeArg::All()); - if (playlist_file_print(r, client.GetPartition(), SongLoader(client), - name, range.start, range.end, true)) - return CommandResult::OK; - - throw PlaylistError::NoSuchList(); + playlist_file_print(r, client.GetPartition(), SongLoader(client), + name, range.start, range.end, true); + return CommandResult::OK; } CommandResult diff --git a/src/playlist/Print.cxx b/src/playlist/Print.cxx index 070eff1bf..84b6a69d4 100644 --- a/src/playlist/Print.cxx +++ b/src/playlist/Print.cxx @@ -13,6 +13,7 @@ #include "thread/Mutex.hxx" #include "Partition.hxx" #include "Instance.hxx" +#include "PlaylistError.hxx" static void playlist_provider_print(Response &r, @@ -48,7 +49,7 @@ playlist_provider_print(Response &r, } } -bool +void playlist_file_print(Response &r, Partition &partition, const SongLoader &loader, const LocatedUri &uri, @@ -68,9 +69,8 @@ playlist_file_print(Response &r, Partition &partition, #endif mutex); if (playlist == nullptr) - return false; + throw PlaylistError::NoSuchList(); playlist_provider_print(r, loader, uri.canonical_uri, *playlist, start_index, end_index, detail); - return true; } diff --git a/src/playlist/Print.hxx b/src/playlist/Print.hxx index e3049796a..487c9af36 100644 --- a/src/playlist/Print.hxx +++ b/src/playlist/Print.hxx @@ -1,8 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-or-later // Copyright The Music Player Daemon Project -#ifndef MPD_PLAYLIST__PRINT_HXX -#define MPD_PLAYLIST__PRINT_HXX +#pragma once class Response; class SongLoader; @@ -11,15 +10,14 @@ struct Partition; /** * Send the playlist file to the client. * + * Throws on error. + * * @param uri the URI of the playlist file in UTF-8 encoding * @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, const SongLoader &loader, const LocatedUri &uri, - unsigned start_index, unsigned end_index, - bool detail); - -#endif + unsigned start_index, unsigned end_index, + bool detail);