From 3656035c89da3174a4c07fd6bf2cc5b455e1315a Mon Sep 17 00:00:00 2001 From: Minijackson Date: Thu, 18 Apr 2019 14:57:03 +0200 Subject: [PATCH] fix(mpd): slightly better and safer error handling --- src/modules/mpd.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/modules/mpd.cpp b/src/modules/mpd.cpp index ae3bc853..ae3ca477 100644 --- a/src/modules/mpd.cpp +++ b/src/modules/mpd.cpp @@ -38,7 +38,8 @@ auto waybar::modules::MPD::update() -> void { if (!wasPlaying && playing()) { periodic_updater().detach(); } - } catch (std::exception e) { + } catch (const std::exception& e) { + std::cerr << module_name_ + ": " + e.what() << std::endl; state_ = MPD_STATE_UNKNOWN; } } @@ -51,7 +52,11 @@ std::thread waybar::modules::MPD::event_listener() { while (true) { if (connection_ == nullptr) { // 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_); } else { waitForEvent();