fix(clock): guard tooltip formatting against unsupported specifiers

Only the label vformat was wrapped in try/catch. An unsupported specifier
(e.g. %-I / %OI) in tooltip-format or the calendar format still threw out
of update() every tick via the calendar/tooltip vformat calls. Wrap the
tooltip-building section in try/catch that warns once and skips the
tooltip for that tick instead of letting the exception escape update().
This commit is contained in:
Alex
2026-07-05 10:13:24 +02:00
parent 88064137ca
commit 34522b4ccd
+15
View File
@@ -220,6 +220,7 @@ auto waybar::modules::Clock::update() -> void {
if (tzInTooltip_) tzText_ = getTZtext(now.get_sys_time());
if (cldInTooltip_) cldText_ = get_calendar(today, shiftedDay, tz);
if (ordInTooltip_) ordText_ = get_ordinal_date(shiftedDay);
try {
if (tzInTooltip_ || cldInTooltip_ || ordInTooltip_) {
// std::vformat doesn't support named arguments.
m_tlpText_ =
@@ -234,6 +235,20 @@ auto waybar::modules::Clock::update() -> void {
}
m_tlpText_ = fmt_lib::vformat(m_locale_, m_tlpText_, fmt_lib::make_format_args(now));
} catch (const std::exception& e) {
// An unsupported/invalid specifier (e.g. %-I / %OI) in the tooltip-format or the
// calendar format must not take the whole module down every tick. Warn once and skip
// the tooltip for this update so the bar keeps working.
static bool tlpWarned = false;
if (!tlpWarned) {
spdlog::warn(
"Clock: could not format tooltip \"{}\": {}. Skipping tooltip; check your "
"tooltip-format/calendar format specifiers.",
m_tlpFmt_, e.what());
tlpWarned = true;
}
m_tlpText_.clear();
}
// Pango doesn't support CSS classes but to continue using it while staying
// backwards compatible this approach uses post-posting to replace fake