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.
This commit is contained in:
maziggy
2026-02-07 10:04:17 +01:00
parent e87a41795c
commit 70e7cba5e7
2 changed files with 6 additions and 0 deletions
+1
View File
@@ -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
+5
View File
@@ -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: