fix(mpd): slightly better and safer error handling

This commit is contained in:
Minijackson 2019-04-18 14:57:03 +02:00
parent 0ce8821aec
commit 3656035c89
No known key found for this signature in database
GPG Key ID: FEA888C9F5D64F62

View File

@ -38,7 +38,8 @@ auto waybar::modules::MPD::update() -> void {
if (!wasPlaying && playing()) { if (!wasPlaying && playing()) {
periodic_updater().detach(); periodic_updater().detach();
} }
} catch (std::exception e) { } catch (const std::exception& e) {
std::cerr << module_name_ + ": " + e.what() << std::endl;
state_ = MPD_STATE_UNKNOWN; state_ = MPD_STATE_UNKNOWN;
} }
} }
@ -51,7 +52,11 @@ std::thread waybar::modules::MPD::event_listener() {
while (true) { while (true) {
if (connection_ == nullptr) { if (connection_ == nullptr) {
// Retry periodically if no connection // Retry periodically if no connection
update(); try {
update();
} catch (const std::exception& e) {
std::cerr << module_name_ + ": " + e.what() << std::endl;
}
std::this_thread::sleep_for(interval_); std::this_thread::sleep_for(interval_);
} else { } else {
waitForEvent(); waitForEvent();