From 1adc2c0c51419f18fb52a75b699b9d1f75d6ca35 Mon Sep 17 00:00:00 2001 From: Michael Herstine Date: Sat, 26 Nov 2022 08:28:10 -0800 Subject: [PATCH] playlist_load_into_queue: log on failure to load song. Log at level error when failing to load a song. Limit the number of log messages produced to avoid flooding the log file when attempting to load a large, broken playlist. Closes #1546 --- src/playlist/PlaylistQueue.cxx | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/playlist/PlaylistQueue.cxx b/src/playlist/PlaylistQueue.cxx index 8500b2b07..89ce1fd1c 100644 --- a/src/playlist/PlaylistQueue.cxx +++ b/src/playlist/PlaylistQueue.cxx @@ -28,6 +28,7 @@ #include "song/DetachedSong.hxx" #include "thread/Mutex.hxx" #include "fs/Traits.hxx" +#include "Log.hxx" #ifdef ENABLE_DATABASE #include "SongLoader.hxx" @@ -41,12 +42,14 @@ playlist_load_into_queue(const char *uri, SongEnumerator &e, playlist &dest, PlayerControl &pc, const SongLoader &loader) { + const unsigned max_log_msgs = 8; + const auto base_uri = uri != nullptr ? PathTraitsUTF8::GetParent(uri) : "."; std::unique_ptr song; - for (unsigned i = 0; + for (unsigned i = 0, failures = 0; i < end_index && (song = e.NextSong()) != nullptr; ++i) { if (i < start_index) { @@ -56,6 +59,12 @@ playlist_load_into_queue(const char *uri, SongEnumerator &e, if (!playlist_check_translate_song(*song, base_uri, loader)) { + failures += 1; + if (failures < max_log_msgs) { + FmtError(playlist_domain, "Failed to load \"{}\".", song->GetURI()); + } else if (failures == max_log_msgs) { + LogError(playlist_domain, "Further errors for this playlist will not be logged."); + } continue; }