From 2b0af30019e75aca4d4f9ab0f5d5bb20b091df4c Mon Sep 17 00:00:00 2001 From: Joe Knapper Date: Fri, 13 Feb 2026 18:48:15 +0000 Subject: [PATCH] Apply suggestions from code review of branch stitching-error-handling Co-authored-by: Julian Stirling --- src/openflexure_microscope_server/stitching.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/openflexure_microscope_server/stitching.py b/src/openflexure_microscope_server/stitching.py index b5c1f58e..6898712d 100644 --- a/src/openflexure_microscope_server/stitching.py +++ b/src/openflexure_microscope_server/stitching.py @@ -270,7 +270,7 @@ class FinalStitcher(BaseStitcher): os.set_blocking(process.stdout.fileno(), False) output_lines = self._log_ongoing(process) returncode = process.wait() - full_output = "".join(output_lines) + full_output = "\n".join(output_lines) if returncode == 0: self.logger.info("Stitching complete") @@ -284,17 +284,19 @@ class FinalStitcher(BaseStitcher): elif returncode == 1: if "No space left on device" in full_output or "Errno 28" in full_output: raise ChildProcessError( - "Not enough space on disk to stitch. Please delete some scans or increase your storage size." + "Not enough space on disk to stitch. Please delete some scans or increase " + "your storage size." ) if ( "Maximum supported image dimension" in full_output or "OSError: broken data stream when writing image file" in full_output ): raise ChildProcessError( - "Scan too big for stitching into a JPEG file. Download the full scan and stitch with alternate settings." + Image dimensions too big for stitching into a JPEG file. Stitched output will exceed the maximum number of pixels in a JPEG (65,535×65,535 pixels). Download the full scan " + "and stitch with alternate settings." ) raise ChildProcessError( - "Stitching errored with exit code 1.\nCheck the logs for more information." + "Unexpected error when stitching (Exit code 1).\nCheck the logs for more information." ) else: raise ChildProcessError( @@ -333,10 +335,7 @@ class FinalStitcher(BaseStitcher): """Log everything currently available in the buffer and return lines.""" lines: list[str] = [] - while True: - line = buffer.readline() - if not line: - break + while line := buffer.readline(): clean = line.rstrip() self.logger.info(clean) lines.append(line)