X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=src%2Fbindings%2Fpython%2Fbt2%2Fbt2%2Ferror.py;h=a067345187c3a646d35f1dc5eda93ebc66ce2b33;hb=768f9bcbf4b5acd09dda85ab32c0ea30d8826136;hp=4e3e53f0314f7a7c5331d97cec45374ed3f48f46;hpb=34d5cf2f1bd49ed027313d94e20f778daaf920af;p=babeltrace.git diff --git a/src/bindings/python/bt2/bt2/error.py b/src/bindings/python/bt2/bt2/error.py index 4e3e53f0..a0673451 100644 --- a/src/bindings/python/bt2/bt2/error.py +++ b/src/bindings/python/bt2/bt2/error.py @@ -1,3 +1,7 @@ +# SPDX-License-Identifier: MIT +# +# Copyright (c) 2019 Simon Marchi + from bt2 import native_bt from collections import abc @@ -26,11 +30,10 @@ class _ErrorCause: self._module_name = native_bt.error_cause_get_module_name(ptr) self._file_name = native_bt.error_cause_get_file_name(ptr) self._line_number = native_bt.error_cause_get_line_number(ptr) + self._str = native_bt.bt2_format_bt_error_cause(ptr) def __str__(self): - s = '[{}] ({}:{})\n'.format(self.module_name, self.file_name, self.line_number) - s += self.message - return s + return self._str @property def message(self): @@ -55,11 +58,11 @@ class _ComponentErrorCause(_ErrorCause): self._component_name = native_bt.error_cause_component_actor_get_component_name( ptr ) - self._component_class_type = native_bt.error_cause_component_actor_get_component_class_type( - ptr + self._component_class_type = ( + native_bt.error_cause_component_actor_get_component_class_type(ptr) ) - self._component_class_name = native_bt.error_cause_component_actor_get_component_class_name( - ptr + self._component_class_name = ( + native_bt.error_cause_component_actor_get_component_class_name(ptr) ) self._plugin_name = native_bt.error_cause_component_actor_get_plugin_name(ptr) @@ -83,11 +86,11 @@ class _ComponentErrorCause(_ErrorCause): class _ComponentClassErrorCause(_ErrorCause): def __init__(self, ptr): super().__init__(ptr) - self._component_class_type = native_bt.error_cause_component_class_actor_get_component_class_type( - ptr + self._component_class_type = ( + native_bt.error_cause_component_class_actor_get_component_class_type(ptr) ) - self._component_class_name = native_bt.error_cause_component_class_actor_get_component_class_name( - ptr + self._component_class_name = ( + native_bt.error_cause_component_class_actor_get_component_class_name(ptr) ) self._plugin_name = native_bt.error_cause_component_class_actor_get_plugin_name( ptr @@ -109,20 +112,22 @@ class _ComponentClassErrorCause(_ErrorCause): class _MessageIteratorErrorCause(_ErrorCause): def __init__(self, ptr): super().__init__(ptr) - self._component_name = native_bt.error_cause_message_iterator_actor_get_component_name( - ptr + self._component_name = ( + native_bt.error_cause_message_iterator_actor_get_component_name(ptr) ) - self._component_output_port_name = native_bt.error_cause_message_iterator_actor_get_component_output_port_name( - ptr + self._component_output_port_name = ( + native_bt.error_cause_message_iterator_actor_get_component_output_port_name( + ptr + ) ) - self._component_class_type = native_bt.error_cause_message_iterator_actor_get_component_class_type( - ptr + self._component_class_type = ( + native_bt.error_cause_message_iterator_actor_get_component_class_type(ptr) ) - self._component_class_name = native_bt.error_cause_message_iterator_actor_get_component_class_name( - ptr + self._component_class_name = ( + native_bt.error_cause_message_iterator_actor_get_component_class_name(ptr) ) - self._plugin_name = native_bt.error_cause_message_iterator_actor_get_plugin_name( - ptr + self._plugin_name = ( + native_bt.error_cause_message_iterator_actor_get_plugin_name(ptr) ) @property @@ -169,6 +174,7 @@ class _Error(Exception, abc.Sequence): assert self._ptr is not None self._msg = msg + self._str = msg + '\n' + native_bt.bt2_format_bt_error(self._ptr) # Read everything we might need from the error pointer, so we don't # depend on it. It's possible for the user to keep an Error object @@ -212,7 +218,4 @@ class _Error(Exception, abc.Sequence): return len(self._causes) def __str__(self): - s = self._msg + '\n' - for c in self: - s += str(c) + '\n' - return s + return self._str