summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
a90c973)
Rename INVALID_OBJECT to UNKNOWN_OBJECT, because it represents better
the situation: the passed object is not necessarily invalid (any string
is a valid object), it's just that the component class doesn't know that
object.
Change its numerical value to something positive, because it should not
be considered as an error (which negative numerical values represent).
A function returning UNKNOWN_OBJECT should not append an error cause.
Also, in the Python bindings, change the default implementation of
_query to raise bt2.UnknownObject instead of NotImplementedError.
NotImplementedError would result in an ERROR status code, whereas
bt2.UnknownObject becomes UNKNOWN_OBJECT. This matches the behavior of
a component class implemented in C, where if it doesn't provide a query
method, it will automatically return UNKNOWN_OBJECT.
Change-Id: Ica1418272b5bf2bbe8e96d639c16f56191151d79
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1760
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
17 files changed:
#undef __BT_FUNC_STATUS_END
#undef __BT_FUNC_STATUS_ERROR
#undef __BT_FUNC_STATUS_INTERRUPTED
#undef __BT_FUNC_STATUS_END
#undef __BT_FUNC_STATUS_ERROR
#undef __BT_FUNC_STATUS_INTERRUPTED
-#undef __BT_FUNC_STATUS_INVALID_OBJECT
+#undef __BT_FUNC_STATUS_UNKNOWN_OBJECT
#undef __BT_FUNC_STATUS_MEMORY_ERROR
#undef __BT_FUNC_STATUS_NOT_FOUND
#undef __BT_FUNC_STATUS_OK
#undef __BT_FUNC_STATUS_MEMORY_ERROR
#undef __BT_FUNC_STATUS_NOT_FOUND
#undef __BT_FUNC_STATUS_OK
# define __BT_FUNC_STATUS_OVERFLOW_ERROR -75
#endif
# define __BT_FUNC_STATUS_OVERFLOW_ERROR -75
#endif
-/* Invalid query object */
-#ifndef __BT_FUNC_STATUS_INVALID_OBJECT
-# define __BT_FUNC_STATUS_INVALID_OBJECT -23
-#endif
/* Memory allocation error */
#ifndef __BT_FUNC_STATUS_MEMORY_ERROR
/* Memory allocation error */
#ifndef __BT_FUNC_STATUS_MEMORY_ERROR
#ifndef __BT_FUNC_STATUS_AGAIN
# define __BT_FUNC_STATUS_AGAIN 11
#endif
#ifndef __BT_FUNC_STATUS_AGAIN
# define __BT_FUNC_STATUS_AGAIN 11
#endif
+
+/* Unknown query object */
+#ifndef __BT_FUNC_STATUS_UNKNOWN_OBJECT
+# define __BT_FUNC_STATUS_UNKNOWN_OBJECT 42
+#endif
BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_AGAIN = __BT_FUNC_STATUS_AGAIN,
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_AGAIN = __BT_FUNC_STATUS_AGAIN,
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_UNKNOWN_OBJECT = __BT_FUNC_STATUS_UNKNOWN_OBJECT,
} 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_AGAIN = __BT_FUNC_STATUS_AGAIN,
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_AGAIN = __BT_FUNC_STATUS_AGAIN,
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_UNKNOWN_OBJECT = __BT_FUNC_STATUS_UNKNOWN_OBJECT,
} bt_query_executor_query_status;
extern
} bt_query_executor_query_status;
extern
'''Raised when an operation fails due to memory issues.'''
'''Raised when an operation fails due to memory issues.'''
-class InvalidObject(Exception):
+class UnknownObject(Exception):
+ '''
+ Raised when a component class handles a query for an object it doesn't
+ know about.
+ '''
+
return int(results_ptr)
def _user_query(cls, query_executor, obj, params, log_level):
return int(results_ptr)
def _user_query(cls, query_executor, obj, params, log_level):
- raise NotImplementedError
+ raise bt2.UnknownObject
def _bt_component_class_ptr(self):
return self._bt_as_component_class_ptr(self._bt_cc_ptr)
def _bt_component_class_ptr(self):
return self._bt_as_component_class_ptr(self._bt_cc_ptr)
static PyObject *py_mod_bt2_exc_memory_error = 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_memory_error = 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_unknown_object_type = NULL;
static
void bt_bt2_cc_init_from_bt2(void)
static
void bt_bt2_cc_init_from_bt2(void)
py_mod_bt2_exc_stop_type =
PyObject_GetAttrString(py_mod_bt2, "Stop");
BT_ASSERT(py_mod_bt2_exc_stop_type);
py_mod_bt2_exc_stop_type =
PyObject_GetAttrString(py_mod_bt2, "Stop");
BT_ASSERT(py_mod_bt2_exc_stop_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_unknown_object_type =
+ PyObject_GetAttrString(py_mod_bt2, "UnknownObject");
+ BT_ASSERT(py_mod_bt2_exc_unknown_object_type);
Py_XDECREF(py_mod_bt2_exc_error_type);
Py_XDECREF(py_mod_bt2_exc_try_again_type);
Py_XDECREF(py_mod_bt2_exc_stop_type);
Py_XDECREF(py_mod_bt2_exc_error_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_unknown_object_type);
py_mod_bt2_exc_stop_type)) {
status = __BT_FUNC_STATUS_END;
} else if (PyErr_GivenExceptionMatches(exc,
py_mod_bt2_exc_stop_type)) {
status = __BT_FUNC_STATUS_END;
} else if (PyErr_GivenExceptionMatches(exc,
- py_mod_bt2_exc_invalid_object_type)) {
- status = __BT_FUNC_STATUS_INVALID_OBJECT;
+ py_mod_bt2_exc_unknown_object_type)) {
+ status = __BT_FUNC_STATUS_UNKNOWN_OBJECT;
} 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._OverflowError
else:
raise bt2._OverflowError(msg)
raise bt2._OverflowError
else:
raise bt2._OverflowError(msg)
- elif status == native_bt.__BT_FUNC_STATUS_INVALID_OBJECT:
+ elif status == native_bt.__BT_FUNC_STATUS_UNKNOWN_OBJECT:
- raise bt2.InvalidObject
+ raise bt2.UnknownObject
- raise bt2.InvalidObject(msg)
+ raise bt2.UnknownObject(msg)
- case BT_QUERY_EXECUTOR_QUERY_STATUS_INVALID_OBJECT:
- *fail_reason = "invalid or unknown query object";
+ case BT_QUERY_EXECUTOR_QUERY_STATUS_UNKNOWN_OBJECT:
+ *fail_reason = "unknown query object";
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";
switch (status) {
case __BT_FUNC_STATUS_OVERFLOW_ERROR:
return "OVERFLOW";
switch (status) {
case __BT_FUNC_STATUS_OVERFLOW_ERROR:
return "OVERFLOW";
- case __BT_FUNC_STATUS_INVALID_OBJECT:
- return "INVALID_OBJECT";
+ case __BT_FUNC_STATUS_UNKNOWN_OBJECT:
+ return "UNKNOWN_OBJECT";
case __BT_FUNC_STATUS_MEMORY_ERROR:
return "MEMORY_ERROR";
case __BT_FUNC_STATUS_ERROR:
case __BT_FUNC_STATUS_MEMORY_ERROR:
return "MEMORY_ERROR";
case __BT_FUNC_STATUS_ERROR:
#define BT_FUNC_STATUS_END __BT_FUNC_STATUS_END
#define BT_FUNC_STATUS_ERROR __BT_FUNC_STATUS_ERROR
#define BT_FUNC_STATUS_INTERRUPTED __BT_FUNC_STATUS_INTERRUPTED
#define BT_FUNC_STATUS_END __BT_FUNC_STATUS_END
#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_UNKNOWN_OBJECT __BT_FUNC_STATUS_UNKNOWN_OBJECT
#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
/* Not an error: nothing to query */
BT_LIB_LOGD("Component class has no registered query method: "
"%!+C", comp_cls);
/* Not an error: nothing to query */
BT_LIB_LOGD("Component class has no registered query method: "
"%!+C", comp_cls);
- status = BT_FUNC_STATUS_INVALID_OBJECT;
+ status = BT_FUNC_STATUS_UNKNOWN_OBJECT;
status = support_info_query(comp_class, params, log_level, result);
} else {
BT_LOGE("Unknown query object `%s`", object);
status = support_info_query(comp_class, params, log_level, result);
} else {
BT_LOGE("Unknown query object `%s`", object);
- status = BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_INVALID_OBJECT;
+ status = BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_UNKNOWN_OBJECT;
log_level);
} else {
BT_COMP_LOGI("Unknown query object `%s`", object);
log_level);
} else {
BT_COMP_LOGI("Unknown query object `%s`", object);
- status = BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_INVALID_OBJECT;
+ status = BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_UNKNOWN_OBJECT;
def _user_consume(self):
pass
def _user_consume(self):
pass
- with self.assertRaises(bt2._Error):
+ with self.assertRaises(bt2.UnknownObject):
bt2.QueryExecutor().query(MySink, 'obj', 23)
def test_query_raises(self):
bt2.QueryExecutor().query(MySink, 'obj', 23)
def test_query_raises(self):
self.assertEqual(cause.component_class_type, bt2.ComponentClassType.SINK)
self.assertEqual(cause.component_class_name, 'MySink')
self.assertEqual(cause.component_class_type, bt2.ComponentClassType.SINK)
self.assertEqual(cause.component_class_name, 'MySink')
- def test_query_invalid_object(self):
+ def test_query_unknown_object(self):
class MySink(bt2._UserSinkComponent):
def _user_consume(self):
pass
@classmethod
def _user_query(cls, query_exec, obj, params, log_level):
class MySink(bt2._UserSinkComponent):
def _user_consume(self):
pass
@classmethod
def _user_query(cls, query_exec, obj, params, log_level):
- raise bt2.InvalidObject
+ raise bt2.UnknownObject
- with self.assertRaises(bt2.InvalidObject):
+ with self.assertRaises(bt2.UnknownObject):
res = bt2.QueryExecutor().query(MySink, 'obj', [17, 23])
def test_query_logging_level_invalid_type(self):
res = bt2.QueryExecutor().query(MySink, 'obj', [17, 23])
def test_query_logging_level_invalid_type(self):
- raise bt2.InvalidObject
+ raise bt2.UnknownObject
@bt2.plugin_component_class
@bt2.plugin_component_class
- raise bt2.InvalidObject
+ raise bt2.UnknownObject
@bt2.plugin_component_class
@bt2.plugin_component_class
- raise bt2.InvalidObject
+ raise bt2.UnknownObject
class TestSourceNoQuery(bt2._UserSourceComponent, message_iterator_class=TestIter):
class TestSourceNoQuery(bt2._UserSourceComponent, message_iterator_class=TestIter):