X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=blobdiff_plain;f=src%2Fbindings%2Fpython%2Fbt2%2Fbt2%2Ferror.py;h=07d24714be423651ed3ab4d1a1205d9fc8ca34ba;hp=dc1e65f55fb03b91e5f2af426468364bac05025c;hb=7d30475f16814c503a3f3188de7bc85dd029d887;hpb=a044251358cc2c1e94f52d12e2fbe99b17b0768c diff --git a/src/bindings/python/bt2/bt2/error.py b/src/bindings/python/bt2/bt2/error.py index dc1e65f5..07d24714 100644 --- a/src/bindings/python/bt2/bt2/error.py +++ b/src/bindings/python/bt2/bt2/error.py @@ -26,11 +26,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): @@ -162,12 +161,15 @@ class _Error(Exception, abc.Sequence): 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 @@ -208,3 +210,6 @@ class _Error(Exception, abc.Sequence): def __len__(self): return len(self._causes) + + def __str__(self): + return self._str