-from bt2 import utils, native_bt
+# SPDX-License-Identifier: MIT
+#
+# Copyright (c) 2019 Simon Marchi <simon.marchi@efficios.com>
+
+from bt2 import native_bt
from collections import abc
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):
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)
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
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
}
-class Error(Exception, abc.Sequence):
+class _Error(Exception, abc.Sequence):
"""
Babeltrace API call error.
the ERROR or MEMORY_ERROR status codes.
"""
- def __init__(self, msg, ptr=None):
+ def __init__(self, msg):
super().__init__(msg)
# Steal the current thread's error.
self._ptr = native_bt.current_thread_take_error()
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
# and to want to read its causes after the error pointer has been
def __len__(self):
return len(self._causes)
+
+ def __str__(self):
+ return self._str