lib: rename INVALID_OBJECT status to UNKNOWN_OBJECT
authorSimon Marchi <simon.marchi@efficios.com>
Wed, 24 Jul 2019 16:11:01 +0000 (12:11 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Fri, 26 Jul 2019 23:19:09 +0000 (19:19 -0400)
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:
include/babeltrace2/babeltrace.h
include/babeltrace2/func-status.h
include/babeltrace2/graph/component-class.h
include/babeltrace2/graph/query-executor.h
src/bindings/python/bt2/bt2/__init__.py
src/bindings/python/bt2/bt2/component.py
src/bindings/python/bt2/bt2/native_bt_component_class.i
src/bindings/python/bt2/bt2/utils.py
src/cli/babeltrace2.c
src/common/common.h
src/lib/func-status.h
src/lib/graph/query-executor.c
src/plugins/ctf/fs-src/fs.c
src/plugins/ctf/lttng-live/lttng-live.c
tests/bindings/python/bt2/test_component_class.py
tests/bindings/python/bt2/test_query_executor.py
tests/data/cli/auto-source-discovery/bt_plugin_test.py

index 3b7bb7538f79722e5784337d5eb6588e803c2598..d4613ca45861bb42a5261568f20e88051d889470 100644 (file)
 #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
index 4f8e61a9ee5c80164f5a04f19871d8fb4e2ba96a..75cee213e689fe83ed719bb30a204558974a7e16 100644 (file)
 # 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
@@ -80,3 +76,8 @@
 #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
index 8a35146c612e6c056a83afad1a44d6c8698834bc..deba3d03959d3c118a1a181a41ef66be65bed8ae 100644 (file)
@@ -50,7 +50,7 @@ typedef enum bt_component_class_query_method_status {
        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 {
index cf6ec244b07fcfb8879acb66de737d2287ab3ad2..460899bdeecd55f5a755f6b79ad85397f13d7e4f 100644 (file)
@@ -42,7 +42,7 @@ typedef enum bt_query_executor_query_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_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
index 313ede9b66c95abe0896fed8e5da7b031494d24a..078ab0d05127858c88135fdfb52fadcbde15c5c9 100644 (file)
@@ -160,7 +160,12 @@ class _MemoryError(_Error):
     '''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.
+    '''
+
     pass
 
 
index 05ebe76114a36b6c79cdea1602d2255c7e2c8222..865ff13598523cc197ec8607d6351339ea14f339 100644 (file)
@@ -603,7 +603,7 @@ class _UserComponentType(type):
         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)
index e71e6bf8e7ed4d1f3e6328fe113ad6ef07e48569..90fc4abae8f1b5a18e9d51d58fda453c18cf889d 100644 (file)
@@ -97,7 +97,7 @@ static PyObject *py_mod_bt2_exc_error_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)
@@ -124,9 +124,9 @@ 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_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);
 }
 
 static
@@ -149,7 +149,7 @@ void bt_bt2_cc_exit_handler(void)
        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);
 }
 
 
@@ -388,8 +388,8 @@ int py_exc_to_status(bt_self_component_class *self_component_class,
                        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,
index a3df357ee47d2184cb82d7a8d070f154c4583250..77ebe606057aeec6d203df13c1f9af491bf2e8d5 100644 (file)
@@ -156,11 +156,11 @@ def _handle_func_status(status, msg=None):
             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:
         if msg is None:
-            raise bt2.InvalidObject
+            raise bt2.UnknownObject
         else:
-            raise bt2.InvalidObject(msg)
+            raise bt2.UnknownObject(msg)
     else:
         assert False
 
index bafda3b5697019d59258ef90ddebd6486b8392c8..8301fba870d676097e90a7f51427bcd97ef6c997 100644 (file)
@@ -173,8 +173,8 @@ int query(struct bt_config *cfg, const bt_component_class *comp_cls,
                        }
 
                        goto error;
-               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";
index 88de75e64348e1da481d2f115187eca69f5634ce..4a2362e34e14be0477d07f47c64c535100ce1e38 100644 (file)
@@ -603,8 +603,8 @@ const char *bt_common_func_status_string(int status)
        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:
index e5aca4aac340953b744ed89a45a0f353d304a34e..d373b3c493fb84787656e29c1e6b3db0c9412dbb 100644 (file)
@@ -34,7 +34,7 @@
 #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
index ce6dd6d9a3dbf2cbb4b5b5a7cc005fe4f65564ce..a602911c374928fa39d54e693ec65415ff14a8e5 100644 (file)
@@ -173,7 +173,7 @@ enum bt_query_executor_query_status bt_query_executor_query(
                /* 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;
                goto end;
        }
 
index e4eb385282ca7dc01916b395ddfe12dbdd6892b6..1ff98131c01d6b2fcff7a585a2b7dd98106c1188 100644 (file)
@@ -2007,7 +2007,7 @@ bt_component_class_query_method_status ctf_fs_query(
                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;
                goto end;
        }
 end:
index df5639b1ca1c38a5480985c8e3b667686a2281d0..124b9d120b5ec95116490b67d021875c8f4aa6ee 100644 (file)
@@ -1456,7 +1456,7 @@ bt_component_class_query_method_status lttng_live_query(
                        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;
                goto end;
        }
 
index fd36d240ccce53284a8e05f30613bcc9fd98c199..aa13cd6aff5f16f64b2a42c5f2758717baba176f 100644 (file)
@@ -184,7 +184,7 @@ class UserComponentClassTestCase(unittest.TestCase):
             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):
index e4f1fa5b14e9a22c1a77f3d62ec12b063acdf703..6d0cc3bdeab6dc920ae87d84c67aeaeecff58091 100644 (file)
@@ -96,16 +96,16 @@ class QueryExecutorTestCase(unittest.TestCase):
         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):
-                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):
index 002e9c33e3474c82a41c7251f9ff1431069a6f26..8c212a3443126382c5b1ca521736f5403dc5967e 100644 (file)
@@ -49,7 +49,7 @@ class TestSourceExt(Base, bt2._UserSourceComponent, message_iterator_class=TestI
             else:
                 return 0
         else:
-            raise bt2.InvalidObject
+            raise bt2.UnknownObject
 
 
 @bt2.plugin_component_class
@@ -72,7 +72,7 @@ class TestSourceSomeDir(
             else:
                 return 0
         else:
-            raise bt2.InvalidObject
+            raise bt2.UnknownObject
 
 
 @bt2.plugin_component_class
@@ -91,7 +91,7 @@ class TestSourceABCDE(Base, bt2._UserSourceComponent, message_iterator_class=Tes
                 else 0.0
             )
         else:
-            raise bt2.InvalidObject
+            raise bt2.UnknownObject
 
 
 class TestSourceNoQuery(bt2._UserSourceComponent, message_iterator_class=TestIter):
This page took 0.032953 seconds and 4 git commands to generate.