Skip to content

Commit e6ee24b

Browse files
committed
Specify explicit cause/context for exceptions
1 parent 22b8636 commit e6ee24b

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

barcode/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ def get(name, code=None, writer=None, options=None):
7171
options = options or {}
7272
try:
7373
barcode = __BARCODE_MAP[name.lower()]
74-
except KeyError:
75-
raise BarcodeNotFoundError(f"The barcode {name!r} you requested is not known.")
74+
except KeyError as e:
75+
raise BarcodeNotFoundError(f"The barcode {name!r} is not known.") from e
7676
if code is not None:
7777
return barcode(code, writer, **options)
7878
else:

barcode/codabar.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,21 @@ def build(self):
4646
) # Start with [A-D], followed by a narrow space
4747

4848
except KeyError:
49-
raise BarcodeError("Codabar should start with either A,B,C or D")
49+
raise BarcodeError("Codabar should start with either A,B,C or D") from None
5050

5151
try:
5252
data += "n".join(
5353
[codabar.CODES[c] for c in self.code[1:-1]]
5454
) # separated by a narrow space
5555
except KeyError:
56-
raise IllegalCharacterError("Codabar can only contain numerics or $:/.+-")
56+
raise IllegalCharacterError(
57+
"Codabar can only contain numerics or $:/.+-"
58+
) from None
5759

5860
try:
5961
data += "n" + codabar.STARTSTOP[self.code[-1]] # End with [A-D]
6062
except KeyError:
61-
raise BarcodeError("Codabar should end with either A,B,C or D")
63+
raise BarcodeError("Codabar should end with either A,B,C or D") from None
6264

6365
raw = ""
6466
for e in data:

0 commit comments

Comments
 (0)