bt2: use format_bt_error and format_bt_error_cause to generate _Error and _ErrorCause...
[babeltrace.git] / src / bindings / python / bt2 / bt2 / error.py
index 773586833b78c8cb81cdc58172716e72317b655c..07d24714be423651ed3ab4d1a1205d9fc8ca34ba 100644 (file)
@@ -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,13 +161,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
+        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 +212,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
This page took 0.02434 seconds and 4 git commands to generate.