From 43862ceb345dc1fadac6b1e55245a049249213d3 Mon Sep 17 00:00:00 2001 From: Viktar Lukashonak Date: Thu, 2 Mar 2023 10:07:10 +0300 Subject: [PATCH 1/2] ISSUE #878. Try catch Clock timezones --- src/modules/clock.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/modules/clock.cpp b/src/modules/clock.cpp index af161d91..ab3a4e0e 100644 --- a/src/modules/clock.cpp +++ b/src/modules/clock.cpp @@ -22,14 +22,20 @@ waybar::modules::Clock::Clock(const std::string& id, const Json::Value& config) is_timezoned_list_in_tooltip_(false) { if (config_["timezones"].isArray() && !config_["timezones"].empty()) { for (const auto& zone_name : config_["timezones"]) { - if (!zone_name.isString() || zone_name.asString().empty()) { - time_zones_.push_back(nullptr); + if (!zone_name.isString() || zone_name.asString().empty()) continue; + try { + time_zones_.push_back(date::locate_zone(zone_name.asString())); + } catch(const std::exception& e) { + spdlog::warn("Timezone: {0}. {1}", zone_name.asString(), e.what()); } - time_zones_.push_back(date::locate_zone(zone_name.asString())); } } else if (config_["timezone"].isString() && !config_["timezone"].asString().empty()) { - time_zones_.push_back(date::locate_zone(config_["timezone"].asString())); + try { + time_zones_.push_back(date::locate_zone(config_["timezone"].asString())); + } catch (const std::exception& e) { + spdlog::warn("Timezone: {0}. {1}", config_["timezone"].asString(), e.what()); + } } // If all timezones are parsed and no one is good, add current time zone. nullptr in timezones From 4cb7e55a915ba04039444a2fa71d1768cb0b3f39 Mon Sep 17 00:00:00 2001 From: Viktar Lukashonak Date: Thu, 2 Mar 2023 10:10:34 +0300 Subject: [PATCH 2/2] ISSUE #878. Try catch Clock timezones Signed-off-by: Viktar Lukashonak --- src/modules/clock.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/modules/clock.cpp b/src/modules/clock.cpp index ab3a4e0e..fb12d2b7 100644 --- a/src/modules/clock.cpp +++ b/src/modules/clock.cpp @@ -22,11 +22,10 @@ waybar::modules::Clock::Clock(const std::string& id, const Json::Value& config) is_timezoned_list_in_tooltip_(false) { if (config_["timezones"].isArray() && !config_["timezones"].empty()) { for (const auto& zone_name : config_["timezones"]) { - if (!zone_name.isString() || zone_name.asString().empty()) - continue; + if (!zone_name.isString() || zone_name.asString().empty()) continue; try { time_zones_.push_back(date::locate_zone(zone_name.asString())); - } catch(const std::exception& e) { + } catch (const std::exception& e) { spdlog::warn("Timezone: {0}. {1}", zone_name.asString(), e.what()); } }