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

This commit is contained in:
Max Kellermann 2024-05-15 20:12:01 +02:00
parent c974fc664c
commit a5456a89dc
3 changed files with 13 additions and 17 deletions

View File

@ -164,11 +164,8 @@ handle_playlistlength(Client &client, Request args, Response &r)
#endif
);
if (playlist_file_length(r, client.GetPartition(), SongLoader(client),
name))
playlist_file_length(r, client.GetPartition(), SongLoader(client), name);
return CommandResult::OK;
throw PlaylistError::NoSuchList();
}
CommandResult

View File

@ -14,6 +14,7 @@
#include "thread/Mutex.hxx"
#include "Partition.hxx"
#include "Instance.hxx"
#include "PlaylistError.hxx"
#include <fmt/format.h>
@ -45,7 +46,7 @@ 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)
@ -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;
}

View File

@ -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