Skip to content

Commit

Permalink
playlist/Length: throw PlaylistError::NoSuchList instead of returning…
Browse files Browse the repository at this point in the history
… false
  • Loading branch information
MaxKellermann committed May 15, 2024
1 parent c974fc6 commit a5456a8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 17 deletions.
7 changes: 2 additions & 5 deletions src/command/PlaylistCommands.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions src/playlist/Length.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "thread/Mutex.hxx"
#include "Partition.hxx"
#include "Instance.hxx"
#include "PlaylistError.hxx"

#include <fmt/format.h>

Expand Down Expand Up @@ -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;

Expand All @@ -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;
}
13 changes: 6 additions & 7 deletions src/playlist/Length.hxx
Original file line number Diff line number Diff line change
@@ -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"

Expand All @@ -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);

0 comments on commit a5456a8

Please sign in to comment.