From 0d5adabf66a65328e37801644ff7f83e5eeed400 Mon Sep 17 00:00:00 2001 From: Thorsten Vitt Date: Tue, 9 Oct 2018 01:18:01 +0200 Subject: [PATCH] Improve error reporting for table exception --- report.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/report.py b/report.py index ed489d2..2e580b0 100644 --- a/report.py +++ b/report.py @@ -115,14 +115,21 @@ def _build_attrs(attrdict: Dict): ' {}="{}"'.format(attr.strip('_').replace('_', '-'), escape(value)) for attr, value in attrdict.items()) def _format_column(self, index, data): - attributes = self._build_attrs(self.attrs[index]) - content = self.formatters[index](data) - return f'{content}' + try: + attributes = self._build_attrs(self.attrs[index]) + content = self.formatters[index](data) + return f'{content}' + except Exception as e: + raise ValueError('Error formatting column %s' % self.titles[index]) from e def _format_row(self, row: Iterable, **rowattrs) -> str: attributes = self._build_attrs(rowattrs) - return f'' + ''.join( - self._format_column(index, column) for index, column in enumerate(row)) + '' + try: + return f'' + ''.join( + self._format_column(index, column) for index, column in enumerate(row)) + '' + except: + logger.exception('Error formatting row %s', row) + return f'Error formatting row {row}' def _format_rows(self, rows: Iterable[Iterable]): for row in rows: