From 5ecd35461bb7ea3ea0283b63ed3f9c6d48731e6e Mon Sep 17 00:00:00 2001 From: dradjenovic Date: Tue, 25 Oct 2022 20:47:10 +0000 Subject: [PATCH] mon: add exception handling to ceph health mute Signed-off-by: Daniel Radjenovic (cherry picked from commit 08abc31359345751432701de36b00d207d3fb6f6) --- src/mon/HealthMonitor.cc | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/mon/HealthMonitor.cc b/src/mon/HealthMonitor.cc index a45159e7c669..4f0f6fe91276 100644 --- a/src/mon/HealthMonitor.cc +++ b/src/mon/HealthMonitor.cc @@ -301,13 +301,19 @@ bool HealthMonitor::prepare_command(MonOpRequestRef op) cmd_getval(cmdmap, "sticky", sticky); string ttl_str; utime_t ttl; + std::chrono::seconds secs; if (cmd_getval(cmdmap, "ttl", ttl_str)) { - auto secs = parse_timespan(ttl_str); - if (secs == 0s) { - r = -EINVAL; - ss << "not a valid duration: " << ttl_str; - goto out; + try { + secs = parse_timespan(ttl_str); + if (secs == 0s) { + throw std::invalid_argument("timespan = 0"); + } + } catch (const std::invalid_argument& e) { + ss << "invalid duration: " << ttl_str << " (" << e.what() << ")"; + r = -EINVAL; + goto out; } + ttl = ceph_clock_now(); ttl += std::chrono::duration(secs).count(); } -- 2.47.3