From 19a6943d6001296619d84594d6f65cea9745e9fb Mon Sep 17 00:00:00 2001 From: Julian Stirling Date: Thu, 19 Feb 2026 17:40:15 +0000 Subject: [PATCH] Use Invocation errors for expected errors. --- src/openflexure_microscope_server/scan_directories.py | 4 +++- src/openflexure_microscope_server/things/autofocus.py | 4 ++-- src/openflexure_microscope_server/things/background_detect.py | 4 ++-- src/openflexure_microscope_server/things/stage_measure.py | 2 +- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/openflexure_microscope_server/scan_directories.py b/src/openflexure_microscope_server/scan_directories.py index a5ddb6fe..ac3c30b5 100644 --- a/src/openflexure_microscope_server/scan_directories.py +++ b/src/openflexure_microscope_server/scan_directories.py @@ -19,6 +19,8 @@ from pydantic import ( model_validator, ) +from labthings_fastapi.exceptions import InvocationError + from openflexure_microscope_server.stitching import StitchingSettings from openflexure_microscope_server.utilities import make_name_safe, requires_lock @@ -34,7 +36,7 @@ SCAN_DATA_FILENAME = "scan_data.json" SCAN_DATA_SCHEMA_VERSION = 2 -class NotEnoughFreeSpaceError(IOError): +class NotEnoughFreeSpaceError(InvocationError): """An exception raised if there is not enough free space on disk to scan.""" diff --git a/src/openflexure_microscope_server/things/autofocus.py b/src/openflexure_microscope_server/things/autofocus.py index 266d4bd1..9001601b 100644 --- a/src/openflexure_microscope_server/things/autofocus.py +++ b/src/openflexure_microscope_server/things/autofocus.py @@ -713,11 +713,11 @@ class AutofocusThing(lt.Thing): return "success", capture_id -class NotAPeakError(RuntimeError): +class NotAPeakError(lt.exceptions.InvocationError): """The data to fit isn't a peak.""" -class NoFocusFoundError(RuntimeError): +class NoFocusFoundError(lt.exceptions.InvocationError): """No focus found during looping Autofocus.""" diff --git a/src/openflexure_microscope_server/things/background_detect.py b/src/openflexure_microscope_server/things/background_detect.py index 3627ca18..15a75064 100644 --- a/src/openflexure_microscope_server/things/background_detect.py +++ b/src/openflexure_microscope_server/things/background_detect.py @@ -19,11 +19,11 @@ SettingsType = TypeVar("SettingsType", bound=BaseModel) BackgroundType = TypeVar("BackgroundType", bound=BaseModel) -class MissingBackgroundDataError(RuntimeError): +class MissingBackgroundDataError(lt.exceptions.InvocationError): """An error raised if checking for sample without background data set.""" -class ChannelBlankError(RuntimeError): +class ChannelBlankError(lt.exceptions.InvocationError): """An error raised if a channel has no measured standard deviation. This is not physical and usually means the camera has not yet booted or changed diff --git a/src/openflexure_microscope_server/things/stage_measure.py b/src/openflexure_microscope_server/things/stage_measure.py index ffd5c1cc..9162d6e9 100644 --- a/src/openflexure_microscope_server/things/stage_measure.py +++ b/src/openflexure_microscope_server/things/stage_measure.py @@ -106,7 +106,7 @@ class RomDataTracker: return {axis: int(turning_loc), other_axis: other_coord, "z": int(turning_z)} -class ParasiticMotionError(Exception): +class ParasiticMotionError(lt.exceptions.InvocationError): """Custom exception raised when parasitic motion is detected. Parasitic motion is when motion in the direction not being measured