Catch error when regex is invalid

This commit is contained in:
Nicolas Mowen 2025-06-19 12:45:21 -06:00
parent fe571dc217
commit 50d27bdfb8

View File

@ -1500,18 +1500,24 @@ class LicensePlateProcessingMixin:
# Determine subLabel based on known plates, use regex matching # Determine subLabel based on known plates, use regex matching
# Default to the detected plate, use label name if there's a match # Default to the detected plate, use label name if there's a match
sub_label = next( try:
( sub_label = next(
label (
for label, plates in self.lpr_config.known_plates.items() label
if any( for label, plates in self.lpr_config.known_plates.items()
re.match(f"^{plate}$", top_plate) if any(
or distance(plate, top_plate) <= self.lpr_config.match_distance re.match(f"^{plate}$", top_plate)
for plate in plates or distance(plate, top_plate) <= self.lpr_config.match_distance
) for plate in plates
), )
None, ),
) None,
)
except re.error:
logger.error(
f"{camera}: Invalid regex in known plates configuration: {self.lpr_config.known_plates}"
)
sub_label = None
# If it's a known plate, publish to sub_label # If it's a known plate, publish to sub_label
if sub_label is not None: if sub_label is not None: