Tweak a few error types.

This commit is contained in:
Julian Stirling 2025-08-21 16:11:30 +01:00
parent 46be2c770e
commit dade26cde1
3 changed files with 10 additions and 5 deletions

View file

@ -33,7 +33,7 @@ def enforce_xy_tuple(value: XYPos) -> XYPos:
:raises ValueError: if the input cannot be coerced to a tuple of length 2. :raises ValueError: if the input cannot be coerced to a tuple of length 2.
""" """
if not isinstance(value, (list, tuple)): if not isinstance(value, (list, tuple)):
raise ValueError("2 value tuple expected") raise TypeError("2 value tuple expected")
if not len(value) == 2: if not len(value) == 2:
raise ValueError("2 value tuple expected") raise ValueError("2 value tuple expected")
if isinstance(value, list): if isinstance(value, list):
@ -49,7 +49,7 @@ def enforce_xyz_tuple(value: XYZPos) -> XYZPos:
:raises ValueError: if the input cannot be coerced to a tuple of length 3. :raises ValueError: if the input cannot be coerced to a tuple of length 3.
""" """
if not isinstance(value, (list, tuple)): if not isinstance(value, (list, tuple)):
raise ValueError("3 value tuple expected") raise TypeError("3 value tuple expected")
if not len(value) == 3: if not len(value) == 3:
raise ValueError("3 value tuple expected") raise ValueError("3 value tuple expected")
if isinstance(value, list): if isinstance(value, list):

View file

@ -61,7 +61,7 @@ def _get_scans_dir(config: dict) -> Optional[str]:
try: try:
return config["things"]["/smart_scan/"]["kwargs"]["scans_folder"] return config["things"]["/smart_scan/"]["kwargs"]["scans_folder"]
except KeyError as e: except KeyError as e:
msg = "Configuration error smart scan should have scans_folder kwarg set" msg = "Configuration error: smart scan should have scans_folder kwarg set"
raise RuntimeError(msg) from e raise RuntimeError(msg) from e
return None return None

View file

@ -26,6 +26,10 @@ from .camera import CameraDependency as CameraClient
from .stage import StageDependency as Stage from .stage import StageDependency as Stage
class NotStreamingError(RuntimeError):
"""No images captured from stream. The camera is almost certainly not streaming."""
class StackParams: class StackParams:
"""A class for holding for stack parameters, and returning computed ones.""" """A class for holding for stack parameters, and returning computed ones."""
@ -310,8 +314,9 @@ class JPEGSharpnessMonitor:
"""Return the z position of the sharpest image on a given move.""" """Return the z position of the sharpest image on a given move."""
_, jpeg_heights, jpeg_sizes = self.move_data(data_index) _, jpeg_heights, jpeg_sizes = self.move_data(data_index)
if len(jpeg_sizes) == 0: if len(jpeg_sizes) == 0:
raise ValueError( raise NotStreamingError(
"No images were captured during the move of the stage. Perhaps the camera is not streaming images?" "No images were captured during the move of the stage. "
"Perhaps the camera is not streaming images?"
) )
return jpeg_heights[np.argmax(jpeg_sizes)] return jpeg_heights[np.argmax(jpeg_sizes)]