bt2: don't show warning when query method raises a non-error exception
authorSimon Marchi <simon.marchi@efficios.com>
Fri, 16 Aug 2019 03:05:13 +0000 (23:05 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Sat, 17 Aug 2019 05:31:37 +0000 (01:31 -0400)
I noticed that when a Python query raised bt2.UnknownObject, we show
this warning:

W BT2-PY component_class_query@native_bt_component_class.i.h:802 Failed to call Python class's _bt_query_from_native() method: py-cls-addr=0x6190001090a0

In my opinion, a query returning "unknown object" is part of the normal
course of operation, and we should not show a warning.  So, only show it
when the exception gets translated to a status < 0.  Also, append an
error cause while at it in case of error.

Change-Id: I079f67b74df881ab000c6e223667ca72dcd52713
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1952
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
src/bindings/python/bt2/bt2/native_bt_component_class.i.h
tests/bindings/python/bt2/test_query_executor.py

index ff736a8057c6e12a73b6d4886a81271a3651c0c4..6774ec6f522f7d8a9230cb555a7162246fa6ed2a 100644 (file)
@@ -799,11 +799,16 @@ bt_component_class_query_method_status component_class_query(
                py_object, py_params_ptr,
                method_data ? method_data : Py_None);
        if (!py_results_addr) {
-               BT_LOG_WRITE_CUR_LVL(BT_LOG_WARNING, log_level, BT_LOG_TAG,
-                       "Failed to call Python class's _bt_query_from_native() method: "
-                       "py-cls-addr=%p", py_cls);
                status = py_exc_to_status_component_class(self_component_class,
                        log_level);
+               if (status < 0) {
+                       static const char *fmt =
+                               "Failed to call Python class's _bt_query_from_native() method: py-cls-addr=%p";
+                       BT_LOG_WRITE_CUR_LVL(BT_LOG_WARNING, log_level, BT_LOG_TAG,
+                               fmt, py_cls);
+                       BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_COMPONENT_CLASS(
+                               self_component_class, fmt, py_cls);
+               }
                goto end;
        }
 
index 3a0e27cb7b7eb1cfb34a08f0cd8feaacf15b4875..62f84d4a50712fbcdff3e82ecb2a61f6e6f350cc 100644 (file)
@@ -171,7 +171,7 @@ class QueryExecutorTestCase(unittest.TestCase):
             res = bt2.QueryExecutor(MySink, 'obj', [17, 23]).query()
 
         exc = ctx.exception
-        self.assertEqual(len(exc), 2)
+        self.assertEqual(len(exc), 3)
         cause = exc[0]
         self.assertIsInstance(cause, bt2._ComponentClassErrorCause)
         self.assertIn('raise ValueError', cause.message)
This page took 0.026246 seconds and 4 git commands to generate.