1
0

qrreader.get_qr_reader: raise instead of returning None

move MissingQrDetectionLib to core lib
This commit is contained in:
SomberNight
2022-06-01 18:52:11 +02:00
parent 01d20cba49
commit 9d125118da
4 changed files with 20 additions and 15 deletions

View File

@@ -35,15 +35,17 @@ from .abstract_base import AbstractQrCodeReader, QrCodeResult
_logger = get_logger(__name__)
class MissingLib(RuntimeError):
''' Raised by underlying implementation if missing libs '''
pass
class MissingQrDetectionLib(RuntimeError):
''' Raised if we can't find zbar or whatever other platform lib
we require to detect QR in image frames. '''
def get_qr_reader() -> Optional[AbstractQrCodeReader]:
def get_qr_reader() -> AbstractQrCodeReader:
"""
Get the Qr code reader for the current platform
Get the Qr code reader for the current platform.
Might raise exception: MissingQrDetectionLib.
"""
excs = []
try:
from .zbar import ZbarQrCodeReader
return ZbarQrCodeReader()
@@ -59,5 +61,13 @@ def get_qr_reader() -> Optional[AbstractQrCodeReader]:
"""
except MissingLib as e:
_logger.exception("")
excs.append(e)
return None
raise MissingQrDetectionLib(f"The platform QR detection library is not available.\nerrors: {excs!r}")
# --- Internals below (not part of external API)
class MissingLib(RuntimeError):
''' Raised by underlying implementation if missing libs '''
pass