]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr: better error handling when reading option 32730/head
authorKefu Chai <kchai@redhat.com>
Mon, 20 Jan 2020 04:02:26 +0000 (12:02 +0800)
committerKefu Chai <kchai@redhat.com>
Thu, 23 Jan 2020 12:18:28 +0000 (20:18 +0800)
this also silences the warning of

src/mgr/BaseMgrModule.cc:402:9: warning: unused variable 'r' [-Wunused-variable]
     int r = g_conf().get_val(string(what), &value);
         ^

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/mgr/BaseMgrModule.cc

index baa8426a42a57c9655daa1b8d8391684024bb00c..ebdec8f0503656b45ee4bca5d559c0a1dd22876d 100644 (file)
@@ -399,13 +399,23 @@ ceph_option_get(BaseMgrModule *self, PyObject *args)
   const Option *opt = g_conf().find_option(string(what));
   if (opt) {
     std::string value;
-    int r = g_conf().get_val(string(what), &value);
-    assert(r >= 0);
+    switch (int r = g_conf().get_val(string(what), &value); r) {
+    case -ENOMEM:
+      PyErr_NoMemory();
+      return nullptr;
+    case -ENAMETOOLONG:
+      PyErr_SetString(PyExc_ValueError, "value too long");
+      return nullptr;
+    default:
+      ceph_assert(r == 0);
+      break;
+    }
     dout(10) << "ceph_option_get " << what << " found: " << value << dendl;
     return get_python_typed_option_value(opt->type, value);
   } else {
     dout(4) << "ceph_option_get " << what << " not found " << dendl;
-    Py_RETURN_NONE;
+    PyErr_Format(PyExc_KeyError, "option not found: %s", what);
+    return nullptr;
   }
 }