From 9885deaa5993c9219dfa39e06fd88ed8732f60ad Mon Sep 17 00:00:00 2001 From: Stephan Sokolow Date: Thu, 22 May 2014 00:47:08 -0400 Subject: [PATCH] Make BarcodeSizeError and BarcodeTypeError display the erroneous value (MUCH more helpful for debugging) --- escpos/escpos.py | 6 +++--- escpos/exceptions.py | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/escpos/escpos.py b/escpos/escpos.py index df74fea..26ec590 100644 --- a/escpos/escpos.py +++ b/escpos/escpos.py @@ -159,12 +159,12 @@ class Escpos: if 1 <= height <= 255: self._raw(BARCODE_HEIGHT + chr(height)) else: - raise BarcodeSizeError() + raise BarcodeSizeError("height = %s" % height) # Width if 2 <= width <= 6: self._raw(BARCODE_WIDTH + chr(width)) else: - raise BarcodeSizeError() + raise BarcodeSizeError("width = %s" % width) # Font if font.upper() == "B": self._raw(BARCODE_FONT_B) @@ -195,7 +195,7 @@ class Escpos: elif bc.upper() == "NW7": self._raw(BARCODE_NW7) else: - raise BarcodeTypeError() + raise BarcodeTypeError(bc) # Print Code if code: self._raw(code) diff --git a/escpos/exceptions.py b/escpos/exceptions.py index caad7a8..f9c7489 100644 --- a/escpos/exceptions.py +++ b/escpos/exceptions.py @@ -34,7 +34,7 @@ class BarcodeTypeError(Error): self.resultcode = 10 def __str__(self): - return "No Barcode type is defined" + return "No Barcode type is defined (%s)" % self.msg class BarcodeSizeError(Error): def __init__(self, msg=""): @@ -43,7 +43,7 @@ class BarcodeSizeError(Error): self.resultcode = 20 def __str__(self): - return "Barcode size is out of range" + return "Barcode size is out of range (%s)" % self.msg class BarcodeCodeError(Error): def __init__(self, msg=""):