bt2/native_bt_component_class.i.h \
bt2/native_bt_connection.i \
bt2/native_bt_error.i \
+ bt2/native_bt_error.i.h \
bt2/native_bt_event.i \
bt2/native_bt_event_class.i \
bt2/native_bt_field.i \
$(top_builddir)/src/autodisc/libbabeltrace2-autodisc.la \
$(top_builddir)/src/logging/libbabeltrace2-logging.la \
$(top_builddir)/src/common/libbabeltrace2-common.la \
- $(top_builddir)/src/py-common/libbabeltrace2-py-common.la
+ $(top_builddir)/src/py-common/libbabeltrace2-py-common.la \
+ $(top_builddir)/src/string-format/libbabeltrace2-string-format.la
GENERATED_BINDINGS_DEPS = \
bt2/native_bt.c \
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):
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
return len(self._causes)
def __str__(self):
- s = self._msg + '\n'
- for c in reversed(self):
- s += str(c) + '\n'
- return s
+ return self._str
--- /dev/null
+/*
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2019 Efficios, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include <string-format/format-error.h>
+
+static
+PyObject *bt_bt2_format_bt_error_cause(const bt_error_cause *error_cause)
+{
+ gchar *error_cause_str;
+ PyObject *py_error_cause_str = NULL;
+
+ error_cause_str = format_bt_error_cause(error_cause, 80,
+ bt_python_bindings_bt2_log_level, BT_COMMON_COLOR_WHEN_NEVER);
+ BT_ASSERT(error_cause_str);
+
+ py_error_cause_str = PyString_FromString(error_cause_str);
+
+ g_free(error_cause_str);
+
+ return py_error_cause_str;
+}
+
+static
+PyObject *bt_bt2_format_bt_error(const bt_error *error)
+{
+ gchar *error_str;
+ PyObject *py_error_str = NULL;
+
+ error_str = format_bt_error(error, 80,
+ bt_python_bindings_bt2_log_level, BT_COMMON_COLOR_WHEN_NEVER);
+ BT_ASSERT(error_str);
+
+ py_error_str = PyString_FromString(error_str);
+
+ g_free(error_str);
+
+ return py_error_str;
+}