]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: add exception handling to ceph health mute 55118/head
authordradjenovic <dradjenovic@digitalocean.com>
Tue, 25 Oct 2022 20:47:10 +0000 (20:47 +0000)
committerPrashant D <pdhange@redhat.com>
Tue, 9 Jan 2024 21:38:24 +0000 (16:38 -0500)
Signed-off-by: Daniel Radjenovic <dradjenovic@digitalocean.com>
(cherry picked from commit 08abc31359345751432701de36b00d207d3fb6f6)

src/mon/HealthMonitor.cc

index a45159e7c669c4e4d4620dbe4fe124430769b4a8..4f0f6fe91276b07267bd8e96fef8d9bd1c98d501 100644 (file)
@@ -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<double>(secs).count();
     }