Merge pull request #32730 from tchaikov/wip-mgr-maybe-unused

mgr: better error handling when reading option

Reviewed-by: Sage Weil <sage@redhat.com>
This commit is contained in:
Kefu Chai 2020-01-26 11:56:10 +08:00 committed by GitHub
commit c63587ae35
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View 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;
}
}