X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=src%2Fbindings%2Fpython%2Fbt2%2Fbt2%2Ferror.py;h=a50827a85b3889d3c86b4fb780d20df4d20b0c0a;hb=23256fd15c8ac7d1faaa3e37d0df2e225e90a6c6;hp=f0b9d8e74da700751d882f14f3b96ff5a73d4412;hpb=694c792bc8f078c02acde68a3390acafbb36b2f4;p=babeltrace.git diff --git a/src/bindings/python/bt2/bt2/error.py b/src/bindings/python/bt2/bt2/error.py index f0b9d8e7..a50827a8 100644 --- a/src/bindings/python/bt2/bt2/error.py +++ b/src/bindings/python/bt2/bt2/error.py @@ -1,4 +1,4 @@ -from bt2 import utils, native_bt +from bt2 import native_bt from collections import abc @@ -162,12 +162,14 @@ 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 + # 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,9 @@ class _Error(Exception, abc.Sequence): def __len__(self): return len(self._causes) + + def __str__(self): + s = self._msg + '\n' + for c in reversed(self): + s += str(c) + '\n' + return s