From a5456a89dcd81d7668ac511cb46e3e70e967e24d Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 15 May 2024 20:12:01 +0200 Subject: [PATCH] playlist/Length: throw PlaylistError::NoSuchList instead of returning false --- src/command/PlaylistCommands.cxx | 7 ++----- src/playlist/Length.cxx | 10 +++++----- src/playlist/Length.hxx | 13 ++++++------- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/command/PlaylistCommands.cxx b/src/command/PlaylistCommands.cxx index 9be27a8426..b6746a68ef 100644 --- a/src/command/PlaylistCommands.cxx +++ b/src/command/PlaylistCommands.cxx @@ -164,11 +164,8 @@ handle_playlistlength(Client &client, Request args, Response &r) #endif ); - if (playlist_file_length(r, client.GetPartition(), SongLoader(client), - name)) - return CommandResult::OK; - - throw PlaylistError::NoSuchList(); + playlist_file_length(r, client.GetPartition(), SongLoader(client), name); + return CommandResult::OK; } CommandResult diff --git a/src/playlist/Length.cxx b/src/playlist/Length.cxx index 56c03cc6f6..146e675fae 100644 --- a/src/playlist/Length.cxx +++ b/src/playlist/Length.cxx @@ -14,6 +14,7 @@ #include "thread/Mutex.hxx" #include "Partition.hxx" #include "Instance.hxx" +#include "PlaylistError.hxx" #include @@ -45,10 +46,10 @@ playlist_provider_length(Response &r, r.Fmt(FMT_STRING("playtime: {}\n"), playtime.RoundS()); } -bool +void playlist_file_length(Response &r, Partition &partition, - const SongLoader &loader, - const LocatedUri &uri) + const SongLoader &loader, + const LocatedUri &uri) { Mutex mutex; @@ -62,8 +63,7 @@ playlist_file_length(Response &r, Partition &partition, #endif mutex); if (playlist == nullptr) - return false; + throw PlaylistError::NoSuchList(); playlist_provider_length(r, loader, uri.canonical_uri, *playlist); - return true; } diff --git a/src/playlist/Length.hxx b/src/playlist/Length.hxx index 053b784c45..2245139d6d 100644 --- a/src/playlist/Length.hxx +++ b/src/playlist/Length.hxx @@ -1,8 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-or-later // Copyright The Music Player Daemon Project -#ifndef MPD_PLAYLIST__LENGTH_HXX -#define MPD_PLAYLIST__LENGTH_HXX +#pragma once #include "client/Response.hxx" @@ -13,12 +12,12 @@ struct Partition; * Count the number of songs and their total playtime (seconds) in the * playlist. * + * Throws on error. + * * @param uri the URI of the playlist file in UTF-8 encoding * @return true on success, false if the playlist does not exist */ -bool +void playlist_file_length(Response &r, Partition &partition, - const SongLoader &loader, - const LocatedUri &uri); - -#endif + const SongLoader &loader, + const LocatedUri &uri);