Gracefully handle failures when asking for a password

Fix for #446 and #447.
This commit is contained in:
Andrzej Rybczak
2021-01-24 16:39:55 +01:00
parent 07cc7aa4f3
commit 541b8d7aab
2 changed files with 22 additions and 6 deletions

View File

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

View File

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