From c146b89e7463f601c5b78bf48d2a69ab2215b391 Mon Sep 17 00:00:00 2001 From: Julian Stirling Date: Tue, 30 Jun 2026 20:33:41 +0100 Subject: [PATCH] Adjust catching of InvocationCancelledError so stiching reports as cancelled Also stop stitching scans that error. This is a legacy from regular errors --- .../things/smart_scan.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/openflexure_microscope_server/things/smart_scan.py b/src/openflexure_microscope_server/things/smart_scan.py index 5afc2e6a..2557d532 100644 --- a/src/openflexure_microscope_server/things/smart_scan.py +++ b/src/openflexure_microscope_server/things/smart_scan.py @@ -313,17 +313,18 @@ class SmartScanThing(OFMThing): # If _scan_data is set then scan started if self._scan_data is not None: self._return_to_starting_position() - if not isinstance(e, scan_directories.NotEnoughFreeSpaceError): - # Don't stitch if drive is full (already logged) - self.logger.info( - "Attempting to stitch and archive the images acquired so far." - ) - self._perform_final_stitch() if self._ongoing_scan is not None: # Save any final messages even if there is an exception. self._ongoing_scan.save_scan_log(self) # Error must be raised so UI gives correct output raise e + except lt.exceptions.InvocationCancelledError as e: + # InvocationCancelledError is caught for scanning but not for stitching + # If raised we still need to save the scan log. + if self._ongoing_scan is not None: + self._ongoing_scan.save_scan_log(self) + # Reraise so the action reports as cancelled if stitching is cancelled. + raise e finally: # However the scan finishes, unset all variables and release lock self._ongoing_scan = None @@ -728,9 +729,10 @@ class SmartScanThing(OFMThing): ) try: final_stitcher.run() - except lt.exceptions.InvocationCancelledError: + except lt.exceptions.InvocationCancelledError as e: # Sleep for 1 second just to allow invocation logs to pass to user. time.sleep(1) + raise e except ChildProcessError as e: self.logger.error(f"Stitching failed: {e}", exc_info=e)