Skip to content

Commit a5901bf

Browse files
committed
Keep row number in exception
1 parent 8b3c551 commit a5901bf

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

aiochsa/exc.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from collections import namedtuple
12
import re
23

34

@@ -10,7 +11,7 @@
1011
re.M,
1112
)
1213

13-
at_row_re = re.compile(r'[(]at row (?P<row>\d+)[)]')
14+
at_row_re = re.compile(r'[(]at row (?P<num>\d+)[)]')
1415

1516
class AiochsaException(Exception):
1617
""" Base class for aiochsa exceptions """
@@ -20,6 +21,9 @@ class ProtocolError(AiochsaException):
2021
""" Error communicating to Clickhouse server """
2122

2223

24+
RowInfo = namedtuple('RowInfo', ['num', 'content'])
25+
26+
2327
class DBException(AiochsaException):
2428
""" Error returned from Clickhouse database """
2529

@@ -41,7 +45,7 @@ def __str__(self):
4145
statement = statement[:200] + '...'
4246
message += f'\n{statement}'
4347
if self.row:
44-
message += f'\n{self.row}'
48+
message += f'\n{self.row.num}: {self.row.content}'
4549
return message
4650

4751
@classmethod
@@ -55,9 +59,9 @@ def from_message(cls, exc_message, *, statement=None, rows=None):
5559
at_row_m = at_row_re.search(display_text)
5660
if at_row_m:
5761
# It's 1-based
58-
row_num = int(at_row_m.group('row'))
62+
row_num = int(at_row_m.group('num'))
5963
if len(rows) >= row_num:
60-
row = rows[row_num - 1]
64+
row = RowInfo(row_num, rows[row_num - 1])
6165

6266
return cls(
6367
code=int(m.group('code')),

tests/test_exc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@ async def test_exc_row(conn, table_test1):
4444
{'amount': Decimal('1234567890.1234567890')},
4545
)
4646
assert exc_info.value.code == error_codes.ARGUMENT_OUT_OF_BOUND
47-
assert exc_info.value.row == '{"amount": 1234567890.1234567890}'
47+
assert exc_info.value.row == (1, '{"amount": 1234567890.1234567890}')

0 commit comments

Comments
 (0)