diff --git a/frigate/app.py b/frigate/app.py index 1306ee97d..d877eca2c 100644 --- a/frigate/app.py +++ b/frigate/app.py @@ -16,6 +16,7 @@ import psutil from peewee_migrate import Router from playhouse.sqlite_ext import SqliteExtDatabase from playhouse.sqliteq import SqliteQueueDatabase +from pydantic import ValidationError from frigate.api.app import create_app from frigate.comms.config_updater import ConfigPublisher @@ -611,8 +612,13 @@ class FrigateApp: print("*************************************************************") print("*** Config Validation Errors ***") print("*************************************************************") - print(e) - print(traceback.format_exc()) + if isinstance(e, ValidationError): + for error in e.errors(): + location = ".".join(error["loc"]) + print(f"{location}: {error['msg']}") + else: + print(e) + print(traceback.format_exc()) print("*************************************************************") print("*** End Config Validation Errors ***") print("*************************************************************") diff --git a/frigate/config.py b/frigate/config.py index 602f03f1f..98f961dcd 100644 --- a/frigate/config.py +++ b/frigate/config.py @@ -555,19 +555,24 @@ class ZoneConfig(BaseModel): # old native resolution coordinates if isinstance(coordinates, list): explicit = any(p.split(",")[0] > "1.0" for p in coordinates) - self._contour = np.array( - [ - ( - [int(p.split(",")[0]), int(p.split(",")[1])] - if explicit - else [ - int(float(p.split(",")[0]) * frame_shape[1]), - int(float(p.split(",")[1]) * frame_shape[0]), - ] - ) - for p in coordinates - ] - ) + try: + self._contour = np.array( + [ + ( + [int(p.split(",")[0]), int(p.split(",")[1])] + if explicit + else [ + int(float(p.split(",")[0]) * frame_shape[1]), + int(float(p.split(",")[1]) * frame_shape[0]), + ] + ) + for p in coordinates + ] + ) + except ValueError: + raise ValueError( + f"Invalid coordinates found in configuration file. Coordinates must be relative (between 0-1): {coordinates}" + ) if explicit: self.coordinates = ",".join( @@ -579,24 +584,29 @@ class ZoneConfig(BaseModel): elif isinstance(coordinates, str): points = coordinates.split(",") explicit = any(p > "1.0" for p in points) - self._contour = np.array( - [ - ( - [int(points[i]), int(points[i + 1])] - if explicit - else [ - int(float(points[i]) * frame_shape[1]), - int(float(points[i + 1]) * frame_shape[0]), - ] - ) - for i in range(0, len(points), 2) - ] - ) + try: + self._contour = np.array( + [ + ( + [int(points[i]), int(points[i + 1])] + if explicit + else [ + int(float(points[i]) * frame_shape[1]), + int(float(points[i + 1]) * frame_shape[0]), + ] + ) + for i in range(0, len(points), 2) + ] + ) + except ValueError: + raise ValueError( + f"Invalid coordinates found in configuration file. Coordinates must be relative (between 0-1): {coordinates}" + ) if explicit: self.coordinates = ",".join( [ - f"{round(int(points[i]) / frame_shape[1], 3)},{round(int(points[i + 1]) / frame_shape[0], 3)}" + f"{int(points[i]) / frame_shape[1]},{int(points[i + 1]) / frame_shape[0]}" for i in range(0, len(points), 2) ] )