From 23d63d2b84cd432012e5e86e3b6a83f6795d3949 Mon Sep 17 00:00:00 2001 From: Alex Date: Sat, 4 Jul 2026 08:46:32 +0200 Subject: [PATCH] fix(clock): degrade gracefully on an invalid format specifier An unsupported specifier (e.g. the %-I / %OI no-leading-zero padding modifiers, which the date/std::chrono formatter does not implement) threw out of update() and the whole clock module failed to load. Catch it, warn once, and fall back to {:%H:%M} so the bar still comes up. Addresses #1469. --- src/modules/clock.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/modules/clock.cpp b/src/modules/clock.cpp index 095ac403..38dec4b2 100644 --- a/src/modules/clock.cpp +++ b/src/modules/clock.cpp @@ -185,7 +185,26 @@ auto waybar::modules::Clock::update() -> void { const auto* tz = tzList_[tzCurrIdx_] != nullptr ? tzList_[tzCurrIdx_] : local_zone(); const zoned_time now{tz, floor(system_clock::now())}; - setLabelMarkup(fmt_lib::vformat(m_locale_, format_, fmt_lib::make_format_args(now))); + try { + setLabelMarkup(fmt_lib::vformat(m_locale_, format_, fmt_lib::make_format_args(now))); + } catch (const std::exception& e) { + // An unsupported/invalid specifier (e.g. the %-I / %OI padding modifiers, which the + // date/std::chrono formatter does not implement) must not take the whole module down. + // Warn once and fall back to a safe default so the bar still loads. + static bool warned = false; + if (!warned) { + spdlog::warn( + "Clock: could not format \"{}\": {}. Falling back to a default; check your format " + "specifiers.", + format_, e.what()); + warned = true; + } + try { + setLabelMarkup(fmt_lib::vformat(m_locale_, "{:%H:%M}", fmt_lib::make_format_args(now))); + } catch (...) { + setLabelMarkup(""); + } + } if (tooltipEnabled()) { const year_month_day today{floor(now.get_local_time())};