From 561e7049fde1116fb0b25d902b8c158b309c8070 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Thu, 15 Aug 2019 23:05:13 -0400 Subject: [PATCH] bt2: don't show warning when query method raises a non-error exception 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 Reviewed-on: https://review.lttng.org/c/babeltrace/+/1952 CI-Build: Philippe Proulx Tested-by: jenkins Reviewed-by: Philippe Proulx --- .../python/bt2/bt2/native_bt_component_class.i.h | 11 ++++++++--- tests/bindings/python/bt2/test_query_executor.py | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/bindings/python/bt2/bt2/native_bt_component_class.i.h b/src/bindings/python/bt2/bt2/native_bt_component_class.i.h index ff736a80..6774ec6f 100644 --- a/src/bindings/python/bt2/bt2/native_bt_component_class.i.h +++ b/src/bindings/python/bt2/bt2/native_bt_component_class.i.h @@ -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; } diff --git a/tests/bindings/python/bt2/test_query_executor.py b/tests/bindings/python/bt2/test_query_executor.py index 3a0e27cb..62f84d4a 100644 --- a/tests/bindings/python/bt2/test_query_executor.py +++ b/tests/bindings/python/bt2/test_query_executor.py @@ -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) -- 2.34.1