This patch removes the INVALID_PARAMS status. It is currently meant to
be used by component classes in query, if they don't get the parameters
they expect (mandatory parameter not present, wrong type, wrong value).
Since we now have a framework to describe errors precisely, this can be
accomplished more simply by returning ERROR and appending an error
cause.
So this patch removes INVALID_PARAMS, replacing all of its uses with
ERROR. It also remove other traces of that status, including in the
Python bindings.
- In lttng-live.c, we were logging a warning when getting invalid
parameters. Since we are now returning an error, I think it makes sense
to log an error. I also think it's something that deserves to be an
error anyway.
- Because queries now return ERROR without appending an error cause and
the library's bt_query_executor_query function doesn't append either, we
get in the case where we construct a bt2._Error and don't have an error
for the current thread. I added some error cause appending in
bt_query_executor_query to fix that, which I think is a valid
improvement on its own. Component classes should ideally also append an
error cause when they return ERROR, but that is left as an exercise for
later.
- The test_query_invalid_params test is removed. Changing raise
bt2.InvalidParams to raise ValueError would just make the test redundant
with test_query_gen_error.
Change-Id: I8c9277aa5e55bb8cde9b23a3aedf217cbe6a5849
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1756
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
15 files changed:
/* Cancel private definitions */
#undef __BT_FUNC_STATUS_AGAIN
#undef __BT_FUNC_STATUS_END
/* Cancel private definitions */
#undef __BT_FUNC_STATUS_AGAIN
#undef __BT_FUNC_STATUS_END
-#undef __BT_FUNC_STATUS_END
-#undef __BT_FUNC_STATUS_ERROR
#undef __BT_FUNC_STATUS_ERROR
#undef __BT_FUNC_STATUS_INTERRUPTED
#undef __BT_FUNC_STATUS_INVALID_OBJECT
#undef __BT_FUNC_STATUS_MEMORY_ERROR
#undef __BT_FUNC_STATUS_NOT_FOUND
#undef __BT_FUNC_STATUS_OK
#undef __BT_FUNC_STATUS_ERROR
#undef __BT_FUNC_STATUS_INTERRUPTED
#undef __BT_FUNC_STATUS_INVALID_OBJECT
#undef __BT_FUNC_STATUS_MEMORY_ERROR
#undef __BT_FUNC_STATUS_NOT_FOUND
#undef __BT_FUNC_STATUS_OK
+#undef __BT_FUNC_STATUS_OVERFLOW
#undef __BT_IN_BABELTRACE_H
#undef __BT_UPCAST
#undef __BT_UPCAST_CONST
#undef __BT_IN_BABELTRACE_H
#undef __BT_UPCAST
#undef __BT_UPCAST_CONST
# define __BT_FUNC_STATUS_OVERFLOW -75
#endif
# define __BT_FUNC_STATUS_OVERFLOW -75
#endif
-/* Invalid query parameters */
-#ifndef __BT_FUNC_STATUS_INVALID_PARAMS
-# define __BT_FUNC_STATUS_INVALID_PARAMS -24
-#endif
-
/* Invalid query object */
#ifndef __BT_FUNC_STATUS_INVALID_OBJECT
# define __BT_FUNC_STATUS_INVALID_OBJECT -23
/* Invalid query object */
#ifndef __BT_FUNC_STATUS_INVALID_OBJECT
# define __BT_FUNC_STATUS_INVALID_OBJECT -23
BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_ERROR = __BT_FUNC_STATUS_ERROR,
BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_MEMORY_ERROR = __BT_FUNC_STATUS_MEMORY_ERROR,
BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_INVALID_OBJECT = __BT_FUNC_STATUS_INVALID_OBJECT,
BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_ERROR = __BT_FUNC_STATUS_ERROR,
BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_MEMORY_ERROR = __BT_FUNC_STATUS_MEMORY_ERROR,
BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_INVALID_OBJECT = __BT_FUNC_STATUS_INVALID_OBJECT,
- BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_INVALID_PARAMS = __BT_FUNC_STATUS_INVALID_PARAMS,
} bt_component_class_query_method_status;
typedef enum bt_component_class_message_iterator_init_method_status {
} bt_component_class_query_method_status;
typedef enum bt_component_class_message_iterator_init_method_status {
BT_QUERY_EXECUTOR_QUERY_STATUS_ERROR = __BT_FUNC_STATUS_ERROR,
BT_QUERY_EXECUTOR_QUERY_STATUS_MEMORY_ERROR = __BT_FUNC_STATUS_MEMORY_ERROR,
BT_QUERY_EXECUTOR_QUERY_STATUS_INVALID_OBJECT = __BT_FUNC_STATUS_INVALID_OBJECT,
BT_QUERY_EXECUTOR_QUERY_STATUS_ERROR = __BT_FUNC_STATUS_ERROR,
BT_QUERY_EXECUTOR_QUERY_STATUS_MEMORY_ERROR = __BT_FUNC_STATUS_MEMORY_ERROR,
BT_QUERY_EXECUTOR_QUERY_STATUS_INVALID_OBJECT = __BT_FUNC_STATUS_INVALID_OBJECT,
- BT_QUERY_EXECUTOR_QUERY_STATUS_INVALID_PARAMS = __BT_FUNC_STATUS_INVALID_PARAMS,
} bt_query_executor_query_status;
extern
} bt_query_executor_query_status;
extern
-class InvalidParams(Exception):
- pass
-
-
class OverflowError(OverflowError):
pass
class OverflowError(OverflowError):
pass
static PyObject *py_mod_bt2_exc_try_again_type = NULL;
static PyObject *py_mod_bt2_exc_stop_type = NULL;
static PyObject *py_mod_bt2_exc_invalid_object_type = NULL;
static PyObject *py_mod_bt2_exc_try_again_type = NULL;
static PyObject *py_mod_bt2_exc_stop_type = NULL;
static PyObject *py_mod_bt2_exc_invalid_object_type = NULL;
-static PyObject *py_mod_bt2_exc_invalid_params_type = NULL;
static
void bt_bt2_cc_init_from_bt2(void)
static
void bt_bt2_cc_init_from_bt2(void)
py_mod_bt2_exc_invalid_object_type =
PyObject_GetAttrString(py_mod_bt2, "InvalidObject");
BT_ASSERT(py_mod_bt2_exc_invalid_object_type);
py_mod_bt2_exc_invalid_object_type =
PyObject_GetAttrString(py_mod_bt2, "InvalidObject");
BT_ASSERT(py_mod_bt2_exc_invalid_object_type);
- py_mod_bt2_exc_invalid_params_type =
- PyObject_GetAttrString(py_mod_bt2, "InvalidParams");
- BT_ASSERT(py_mod_bt2_exc_invalid_params_type);
Py_XDECREF(py_mod_bt2_exc_try_again_type);
Py_XDECREF(py_mod_bt2_exc_stop_type);
Py_XDECREF(py_mod_bt2_exc_invalid_object_type);
Py_XDECREF(py_mod_bt2_exc_try_again_type);
Py_XDECREF(py_mod_bt2_exc_stop_type);
Py_XDECREF(py_mod_bt2_exc_invalid_object_type);
- Py_XDECREF(py_mod_bt2_exc_invalid_params_type);
} else if (PyErr_GivenExceptionMatches(exc,
py_mod_bt2_exc_invalid_object_type)) {
status = __BT_FUNC_STATUS_INVALID_OBJECT;
} else if (PyErr_GivenExceptionMatches(exc,
py_mod_bt2_exc_invalid_object_type)) {
status = __BT_FUNC_STATUS_INVALID_OBJECT;
- } else if (PyErr_GivenExceptionMatches(exc,
- py_mod_bt2_exc_invalid_params_type)) {
- status = __BT_FUNC_STATUS_INVALID_PARAMS;
} else {
/* Unknown exception: convert to general error */
log_exception_and_maybe_append_error(BT_LOG_WARNING, true,
} else {
/* Unknown exception: convert to general error */
log_exception_and_maybe_append_error(BT_LOG_WARNING, true,
raise bt2.InvalidObject
else:
raise bt2.InvalidObject(msg)
raise bt2.InvalidObject
else:
raise bt2.InvalidObject(msg)
- elif status == native_bt.__BT_FUNC_STATUS_INVALID_PARAMS:
- if msg is None:
- raise bt2.InvalidParams
- else:
- raise bt2.InvalidParams(msg)
case BT_QUERY_EXECUTOR_QUERY_STATUS_INVALID_OBJECT:
*fail_reason = "invalid or unknown query object";
goto error;
case BT_QUERY_EXECUTOR_QUERY_STATUS_INVALID_OBJECT:
*fail_reason = "invalid or unknown query object";
goto error;
- case BT_QUERY_EXECUTOR_QUERY_STATUS_INVALID_PARAMS:
- *fail_reason = "invalid query parameters";
- goto error;
case BT_QUERY_EXECUTOR_QUERY_STATUS_MEMORY_ERROR:
*fail_reason = "not enough memory";
goto error;
case BT_QUERY_EXECUTOR_QUERY_STATUS_MEMORY_ERROR:
*fail_reason = "not enough memory";
goto error;
switch (status) {
case __BT_FUNC_STATUS_OVERFLOW:
return "OVERFLOW";
switch (status) {
case __BT_FUNC_STATUS_OVERFLOW:
return "OVERFLOW";
- case __BT_FUNC_STATUS_INVALID_PARAMS:
- return "INVALID_PARAMS";
case __BT_FUNC_STATUS_INVALID_OBJECT:
return "INVALID_OBJECT";
case __BT_FUNC_STATUS_MEMORY_ERROR:
case __BT_FUNC_STATUS_INVALID_OBJECT:
return "INVALID_OBJECT";
case __BT_FUNC_STATUS_MEMORY_ERROR:
#define BT_FUNC_STATUS_ERROR __BT_FUNC_STATUS_ERROR
#define BT_FUNC_STATUS_INTERRUPTED __BT_FUNC_STATUS_INTERRUPTED
#define BT_FUNC_STATUS_INVALID_OBJECT __BT_FUNC_STATUS_INVALID_OBJECT
#define BT_FUNC_STATUS_ERROR __BT_FUNC_STATUS_ERROR
#define BT_FUNC_STATUS_INTERRUPTED __BT_FUNC_STATUS_INTERRUPTED
#define BT_FUNC_STATUS_INVALID_OBJECT __BT_FUNC_STATUS_INVALID_OBJECT
-#define BT_FUNC_STATUS_INVALID_PARAMS __BT_FUNC_STATUS_INVALID_PARAMS
#define BT_FUNC_STATUS_MEMORY_ERROR __BT_FUNC_STATUS_MEMORY_ERROR
#define BT_FUNC_STATUS_NOT_FOUND __BT_FUNC_STATUS_NOT_FOUND
#define BT_FUNC_STATUS_OK __BT_FUNC_STATUS_OK
#define BT_FUNC_STATUS_MEMORY_ERROR __BT_FUNC_STATUS_MEMORY_ERROR
#define BT_FUNC_STATUS_NOT_FOUND __BT_FUNC_STATUS_NOT_FOUND
#define BT_FUNC_STATUS_OK __BT_FUNC_STATUS_OK
"User method returned `BT_FUNC_STATUS_OK` without a result.");
status = (int) query_status;
"User method returned `BT_FUNC_STATUS_OK` without a result.");
status = (int) query_status;
+ if (status < 0) {
+ BT_LIB_LOGW_APPEND_CAUSE(
+ "Component class's \"query\" method failed: "
+ "query-exec-addr=%p, %![cc-]+C, object=\"%s\", "
+ "%![params-]+v, log-level=%s", query_exec, comp_cls,
+ object, params, bt_common_logging_level_string(log_level));
+ goto end;
+ }
+
if (!bt_value_is_map(params)) {
BT_LOGE_STR("Query parameters is not a map value object.");
if (!bt_value_is_map(params)) {
BT_LOGE_STR("Query parameters is not a map value object.");
- status = BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_INVALID_PARAMS;
+ status = BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_ERROR;
goto error;
}
path_value = bt_value_map_borrow_entry_value_const(params, "path");
if (!path_value) {
BT_LOGE_STR("Mandatory `path` parameter missing");
goto error;
}
path_value = bt_value_map_borrow_entry_value_const(params, "path");
if (!path_value) {
BT_LOGE_STR("Mandatory `path` parameter missing");
- status = BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_INVALID_PARAMS;
+ status = BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_ERROR;
goto error;
}
if (!bt_value_is_string(path_value)) {
BT_LOGE_STR("`path` parameter is required to be a string value");
goto error;
}
if (!bt_value_is_string(path_value)) {
BT_LOGE_STR("`path` parameter is required to be a string value");
- status = BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_INVALID_PARAMS;
+ status = BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_ERROR;
if (!bt_value_is_map(params)) {
BT_LOGE("Query parameters is not a map value object.");
if (!bt_value_is_map(params)) {
BT_LOGE("Query parameters is not a map value object.");
- status = BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_INVALID_PARAMS;
+ status = BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_ERROR;
}
if (!read_src_fs_parameters(params, &inputs_value, ctf_fs)) {
}
if (!read_src_fs_parameters(params, &inputs_value, ctf_fs)) {
- status = BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_INVALID_PARAMS;
+ status = BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_ERROR;
url_value = bt_value_map_borrow_entry_value_const(params, URL_PARAM);
if (!url_value) {
url_value = bt_value_map_borrow_entry_value_const(params, URL_PARAM);
if (!url_value) {
- BT_COMP_LOGW("Mandatory `%s` parameter missing", URL_PARAM);
- status = BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_INVALID_PARAMS;
+ BT_COMP_LOGE("Mandatory `%s` parameter missing", URL_PARAM);
+ status = BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_ERROR;
goto error;
}
if (!bt_value_is_string(url_value)) {
goto error;
}
if (!bt_value_is_string(url_value)) {
- BT_COMP_LOGW("`%s` parameter is required to be a string value",
+ BT_COMP_LOGE("`%s` parameter is required to be a string value",
- status = BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_INVALID_PARAMS;
+ status = BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_ERROR;
res = bt2.QueryExecutor().query(MySink, 'obj', [17, 23])
exc = ctx.exception
res = bt2.QueryExecutor().query(MySink, 'obj', [17, 23])
exc = ctx.exception
- self.assertEqual(len(exc), 1)
+ self.assertEqual(len(exc), 2)
cause = exc[0]
self.assertIsInstance(cause, bt2.error._ComponentClassErrorCause)
self.assertIn('raise ValueError', cause.message)
cause = exc[0]
self.assertIsInstance(cause, bt2.error._ComponentClassErrorCause)
self.assertIn('raise ValueError', cause.message)
with self.assertRaises(ValueError):
res = bt2.QueryExecutor().query(MySink, 'obj', [17, 23], 12345)
with self.assertRaises(ValueError):
res = bt2.QueryExecutor().query(MySink, 'obj', [17, 23], 12345)
- def test_query_invalid_params(self):
- class MySink(bt2._UserSinkComponent):
- def _consume(self):
- pass
-
- def _graph_is_configured(self):
- pass
-
- @classmethod
- def _query(cls, query_exec, obj, params, log_level):
- raise bt2.InvalidParams
-
- with self.assertRaises(bt2.InvalidParams):
- res = bt2.QueryExecutor().query(MySink, 'obj', [17, 23])
-
def test_query_try_again(self):
class MySink(bt2._UserSinkComponent):
def _consume(self):
def test_query_try_again(self):
class MySink(bt2._UserSinkComponent):
def _consume(self):
self._check(trace, -2000000002)
def test_clock_class_offset_s_wrong_type(self):
self._check(trace, -2000000002)
def test_clock_class_offset_s_wrong_type(self):
- with self.assertRaises(bt2.InvalidParams):
+ with self.assertRaises(bt2._Error):
self._executor.query(
self._fs,
'trace-info',
self._executor.query(
self._fs,
'trace-info',
)
def test_clock_class_offset_s_wrong_type_none(self):
)
def test_clock_class_offset_s_wrong_type_none(self):
- with self.assertRaises(bt2.InvalidParams):
+ with self.assertRaises(bt2._Error):
self._executor.query(
self._fs,
'trace-info',
self._executor.query(
self._fs,
'trace-info',
)
def test_clock_class_offset_ns_wrong_type(self):
)
def test_clock_class_offset_ns_wrong_type(self):
- with self.assertRaises(bt2.InvalidParams):
+ with self.assertRaises(bt2._Error):
self._executor.query(
self._fs,
'trace-info',
self._executor.query(
self._fs,
'trace-info',
)
def test_clock_class_offset_ns_wrong_type_none(self):
)
def test_clock_class_offset_ns_wrong_type_none(self):
- with self.assertRaises(bt2.InvalidParams):
+ with self.assertRaises(bt2._Error):
self._executor.query(
self._fs,
'trace-info',
self._executor.query(
self._fs,
'trace-info',