From c417577b9cf19e00f92d583f3c82ff95c9e54efe Mon Sep 17 00:00:00 2001 From: emkael Date: Thu, 30 May 2019 00:02:54 +0200 Subject: Error reporting improved --- dealconvert/formats/ber.py | 2 +- dealconvert/formats/bhg.py | 2 +- dealconvert/formats/bri.py | 2 +- dealconvert/formats/dlm.py | 2 +- dealconvert/formats/rzd.py | 4 +++- 5 files changed, 7 insertions(+), 5 deletions(-) (limited to 'dealconvert/formats') diff --git a/dealconvert/formats/ber.py b/dealconvert/formats/ber.py index 54ffd37..1ddd6c8 100644 --- a/dealconvert/formats/ber.py +++ b/dealconvert/formats/ber.py @@ -50,7 +50,7 @@ class BERFormat(DealFormat): deal_str[j*13 + self.cards.index(card)] = str(i + 1) except ValueError: raise RuntimeError( - 'invalid card character: %s' % (card)) + 'invalid card character: %s in board %d' % (card, board.number)) if ' ' in deal_str: warnings.warn('not all cards present in board %d' % ( board.number)) diff --git a/dealconvert/formats/bhg.py b/dealconvert/formats/bhg.py index 23a1673..08b9213 100644 --- a/dealconvert/formats/bhg.py +++ b/dealconvert/formats/bhg.py @@ -51,7 +51,7 @@ class BHGFormat(DealFormat): line += chr((65 if card < 26 else 71)+card) except ValueError: raise RuntimeError( - 'invalid suit %s in board #%d' % ( + 'invalid suit %s in board %d' % ( ''.join(suit), deal.number)) lines[deal.number] = line out_file.write('\r\n'.join(lines)) diff --git a/dealconvert/formats/bri.py b/dealconvert/formats/bri.py index 942c4e4..1a4cc0f 100644 --- a/dealconvert/formats/bri.py +++ b/dealconvert/formats/bri.py @@ -67,5 +67,5 @@ class BRIFormat(DealFormat): deal_str += '%02d' % (self.cards.index(card) + 13*i + 1) except ValueError: raise RuntimeError( - 'invalid card character: %s' % (card)) + 'invalid card character: %s in board %d' % (card, deal.number)) return deal_str diff --git a/dealconvert/formats/dlm.py b/dealconvert/formats/dlm.py index db9ac79..f99cde4 100644 --- a/dealconvert/formats/dlm.py +++ b/dealconvert/formats/dlm.py @@ -98,7 +98,7 @@ class DLMFormat(DealFormat): try: values[suit*13+self.cards.index(card)] = i except ValueError: - raise RuntimeError('invalid card: %s' % (card)) + raise RuntimeError('invalid card: %s in board %d' % (card, board)) line = 'Board %02d=' % (board) checksum = board for i in range(0, 26): diff --git a/dealconvert/formats/rzd.py b/dealconvert/formats/rzd.py index 8ca1e97..93dbc45 100644 --- a/dealconvert/formats/rzd.py +++ b/dealconvert/formats/rzd.py @@ -51,11 +51,13 @@ class RZDFormat(DealFormat): try: idx = self.cards.index(card) except ValueError: - raise RuntimeError('invalid card: %s' % (card)) + raise RuntimeError('invalid card: %s in board %d' % (card, deal.number)) values[idx*4+suit] = (i + offset)%4 for i in range(0, 13): byte = 0 for j in range(0, 4): + if values[4*i+j] is None: + raise RuntimeError('missing card: %s%s in board %d' % ('SHDC'[j], self.cards[i], deal.number)) byte *= 4 byte += values[4*i+j] value += chr(byte) -- cgit v1.2.3 From 674e71ef10bee715e4d43d1b5efd714f96c6df1f Mon Sep 17 00:00:00 2001 From: emkael Date: Fri, 31 May 2019 17:12:15 +0200 Subject: Precautions against empty deal sets --- dealconvert/formats/__init__.py | 2 ++ dealconvert/formats/bhg.py | 2 +- dealconvert/formats/dlm.py | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) (limited to 'dealconvert/formats') diff --git a/dealconvert/formats/__init__.py b/dealconvert/formats/__init__.py index eea9fc6..9c37cf9 100644 --- a/dealconvert/formats/__init__.py +++ b/dealconvert/formats/__init__.py @@ -8,6 +8,8 @@ class DealFormat(object): return self.parse_content(content) def output(self, output_file, deal): + if not len(deal): + raise RuntimeError('Dealset is empty') with open(output_file, 'wb') as out_file: return self.output_content(out_file, deal) diff --git a/dealconvert/formats/bhg.py b/dealconvert/formats/bhg.py index 08b9213..6964ea3 100644 --- a/dealconvert/formats/bhg.py +++ b/dealconvert/formats/bhg.py @@ -40,7 +40,7 @@ class BHGFormat(DealFormat): return deals def output_content(self, out_file, dealset): - lines = [''] * (max([board.number for board in dealset])+2) + lines = [''] * (max([board.number for board in dealset])+2) if len(dealset) else [] for deal in dealset: line = '' for hand in range(0, 4): diff --git a/dealconvert/formats/dlm.py b/dealconvert/formats/dlm.py index f99cde4..56f6e5d 100644 --- a/dealconvert/formats/dlm.py +++ b/dealconvert/formats/dlm.py @@ -66,7 +66,7 @@ class DLMFormat(DealFormat): def output_content(self, out_file, dealset): dealset = dealset[0:99] board_numbers = [deal.number for deal in dealset] - first_board = min(board_numbers) + first_board = min(board_numbers) if len(board_numbers) else 1 board_count = len(dealset) for board in range(first_board, first_board+board_count): if board not in board_numbers: -- cgit v1.2.3