Skip to content

Commit

Permalink
adding exception when grabbing fails
Browse files Browse the repository at this point in the history
  • Loading branch information
timmarkhuff committed Jul 17, 2024
1 parent ea8311e commit 1a4608a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "framegrab"
version = "0.5.3"
version = "0.5.4"
description = "Easily grab frames from cameras or streams"
authors = ["Groundlight <info@groundlight.ai>"]
license = "MIT"
Expand Down
1 change: 1 addition & 0 deletions src/framegrab/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from .cli.clitools import preview_image
from .grabber import FrameGrabber
from .motion import MotionDetector
from .exceptions import GrabError
from .rtsp_discovery import AutodiscoverModes, ONVIFDeviceInfo, RTSPDiscovery

try:
Expand Down
6 changes: 6 additions & 0 deletions src/framegrab/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class GrabError(Exception):
"""Exception raised for errors in the frame grabbing process.
"""
def __init__(self, message="Failed to grab frame from camera."):
self.message = message
super().__init__(self.message)
6 changes: 6 additions & 0 deletions src/framegrab/grabber.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import yaml

from .unavailable_module import UnavailableModule
from .exceptions import GrabError

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -326,6 +327,11 @@ def grab(self) -> np.ndarray:
"""
frame = self._grab_implementation()

if frame is None:
name = self.config['name'] # all grabbers should have a name, either user-provided or generated
error_msg = f'Failed to grab frame from {name}'
raise GrabError(error_msg)

# apply post processing operations
frame = self._crop(frame)
frame = self._digital_zoom(frame)
Expand Down

0 comments on commit 1a4608a

Please sign in to comment.