From 70e7cba5e7dfaa8069e585e7dbb54a6410370e6b Mon Sep 17 00:00:00 2001 From: maziggy Date: Sat, 7 Feb 2026 10:04:00 +0100 Subject: [PATCH] Fix FTP download reporting success on 0-byte files download_to_file() returned True when retrbinary transferred 0 bytes without raising an exception. This caused the /cover endpoint to hit the empty file check and raise HTTP 500 instead of retrying or returning 404. Now treats 0-byte downloads as failures, allowing the cover endpoint's retry logic to work and falling back to 404 if all attempts fail. --- CHANGELOG.md | 1 + backend/app/services/bambu_ftp.py | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6327a3582..8b2e00bd6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ All notable changes to Bambuddy will be documented in this file. - Changed all FTP exception handlers from `except (OSError, ftplib.error_reply)` to `except (OSError, ftplib.Error)` to catch all FTP error types - **HTTP 500 on Reprint and Print Endpoints** — Fixed 500 errors on `/api/v1/archives/{id}/reprint` and `/api/v1/library/files/{id}/print` caused by the FTP failure above - **Exception Handling Reverted** — Reverted overly-narrow exception handling introduced in 0.1.8 that could cause uncaught errors in archive parsing, HTTP clients, 3MF/ZIP processing, Home Assistant, and firmware checks +- **HTTP 500 on Printer Cover Image** — Fixed 500 error on `/api/v1/printers/{id}/cover` when FTP download returned 0 bytes but reported success; now retries and falls back to 404 - **4-Segment Version Support** — Version parser now supports patch releases like `0.1.8.1` for hotfixes without incrementing the minor version ## [0.1.8] - 2026-02-06 diff --git a/backend/app/services/bambu_ftp.py b/backend/app/services/bambu_ftp.py index abc8ca343..4030a2082 100644 --- a/backend/app/services/bambu_ftp.py +++ b/backend/app/services/bambu_ftp.py @@ -269,6 +269,11 @@ class BambuFTPClient: f.flush() os.fsync(f.fileno()) file_size = local_path.stat().st_size if local_path.exists() else 0 + if file_size == 0: + logger.warning("FTP download returned 0 bytes for %s", remote_path) + if local_path.exists(): + local_path.unlink() + return False logger.info("Successfully downloaded %s to %s (%s bytes)", remote_path, local_path, file_size) return True except (OSError, ftplib.Error) as e: