Skip to content

Commit

Permalink
Improve error reporting for table exception
Browse files Browse the repository at this point in the history
  • Loading branch information
thvitt committed Oct 8, 2018
1 parent e7d248f commit 0d5adab
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions report.py
Expand Up @@ -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'<td{attributes}>{content}</td>'
try:
attributes = self._build_attrs(self.attrs[index])
content = self.formatters[index](data)
return f'<td{attributes}>{content}</td>'
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'<tr{attributes}>' + ''.join(
self._format_column(index, column) for index, column in enumerate(row)) + '</tr>'
try:
return f'<tr{attributes}>' + ''.join(
self._format_column(index, column) for index, column in enumerate(row)) + '</tr>'
except:
logger.exception('Error formatting row %s', row)
return f'<tr class="pure-alert pure-error"><td>Error formatting row {row}</td></tr>'

def _format_rows(self, rows: Iterable[Iterable]):
for row in rows:
Expand Down

0 comments on commit 0d5adab

Please sign in to comment.