qrreader.get_qr_reader: raise instead of returning None
move MissingQrDetectionLib to core lib
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user