From 985def83dc88028f0d2a3dc95b76792e24ff966c Mon Sep 17 00:00:00 2001 From: Andrzej Rybczak Date: Sun, 20 Dec 2020 14:58:41 +0100 Subject: [PATCH] Recover from invalid directory in Browser::locateSong --- src/screens/browser.cpp | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/src/screens/browser.cpp b/src/screens/browser.cpp index 21069cc8..e47bedfd 100644 --- a/src/screens/browser.cpp +++ b/src/screens/browser.cpp @@ -427,18 +427,29 @@ void Browser::locateSong(const MPD::Song &s) w.clearFilter(); - // change to relevant directory - if (m_current_directory != s.getDirectory()) + try { - getDirectory(s.getDirectory()); - drawHeader(); - } + // Try to change to relevant directory. + if (m_current_directory != s.getDirectory()) + { + getDirectory(s.getDirectory()); + drawHeader(); + } - // highlight the item - auto begin = w.beginV(), end = w.endV(); - auto it = std::find(begin, end, MPD::Item(s)); - if (it != end) - w.highlight(it-begin); + // Highlight the item. + auto begin = w.beginV(), end = w.endV(); + auto it = std::find(begin, end, MPD::Item(s)); + if (it != end) + w.highlight(it-begin); + } + catch (MPD::ServerError &err) + { + // If the directory is invalid, recover by invoking the update. + if (err.code() == MPD_SERVER_ERROR_NO_EXIST) + requestUpdate(); + else + throw; + } } bool Browser::enterDirectory()