diff --git a/CHANGELOG.md b/CHANGELOG.md index 206ceb05..228bcf68 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # ncmpcpp-0.9.2 (????-??-??) * Revert suppression of output of all external commands as that makes e.g album art addons no longer work. +* Gracefully handle failures when asking for a password. # ncmpcpp-0.9.1 (2020-12-23) * Add support for fetching lyrics from musixmatch.com. diff --git a/src/status.cpp b/src/status.cpp index 9a3cacb1..6e86f478 100644 --- a/src/status.cpp +++ b/src/status.cpp @@ -192,14 +192,29 @@ void Status::handleServerError(MPD::ServerError &e) Statusbar::printf("MPD: %1%", e.what()); if (e.code() == MPD_SERVER_ERROR_PERMISSION) { - NC::Window::ScopedPromptHook helper(*wFooter, nullptr); - Statusbar::put() << "Password: "; - Mpd.SetPassword(wFooter->prompt("", -1, true)); - try { + try + { + NC::Window::ScopedPromptHook helper(*wFooter, nullptr); + Statusbar::put() << "Password: "; + Mpd.SetPassword(wFooter->prompt("", -1, true)); Mpd.SendPassword(); Statusbar::print("Password accepted"); - } catch (MPD::ServerError &e_prim) { - handleServerError(e_prim); + } + // SendPassword might throw if connection is closed + catch (MPD::ClientError &e_prim) + { + handleClientError(e_prim); + } + // Wrong password, we'll ask again later + catch (MPD::ServerError &e_prim) + { + Statusbar::printf("MPD: %1%", e_prim.what()); + } + // If prompt asking for a password is aborted, exit the application to + // prevent getting stuck in the prompt indefinitely. + catch (NC::PromptAborted &) + { + Actions::ExitMainLoop = true; } } }