From 822dbd35b254d4d667877bdad97de091b01fd0ed Mon Sep 17 00:00:00 2001 From: paul2212 Date: Sat, 7 Mar 2026 14:40:12 +0100 Subject: [PATCH] Handle BLE connect TimeoutError and bump to 0.1.11 --- CHANGELOG.md | 5 +++++ fichero/printer.py | 6 ++++++ fichero_printer/CHANGELOG.md | 4 ++++ fichero_printer/config.yaml | 2 +- fichero_printer/fichero/printer.py | 6 ++++++ pyproject.toml | 2 +- 6 files changed, 23 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 38c03e1..185019c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ All notable changes to this project are documented in this file. The format is based on Keep a Changelog and this project uses Semantic Versioning. +## [0.1.11] - 2026-03-07 + +### Fixed +- Handled `asyncio.TimeoutError` from BLE connect path so connection timeouts now return mapped API errors (502) instead of unhandled 500 exceptions. + ## [0.1.10] - 2026-03-07 ### Changed diff --git a/fichero/printer.py b/fichero/printer.py index 0773645..821b492 100644 --- a/fichero/printer.py +++ b/fichero/printer.py @@ -419,6 +419,12 @@ async def connect( await pc.start() yield pc return + except asyncio.TimeoutError as exc: + last_exc = exc + if attempt < BLE_CONNECT_RETRIES: + await asyncio.sleep(BLE_CONNECT_BACKOFF * attempt) + continue + raise PrinterError(f"BLE connection timed out: {exc}") from exc except BleakDBusError as exc: msg = str(exc).lower() if "br-connection-not-supported" in msg: diff --git a/fichero_printer/CHANGELOG.md b/fichero_printer/CHANGELOG.md index 39d2acb..c2c856b 100644 --- a/fichero_printer/CHANGELOG.md +++ b/fichero_printer/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 0.1.11 + +- Fixed unhandled BLE connect timeout (`asyncio.TimeoutError`) that previously caused HTTP 500 responses. + ## 0.1.10 - Added automatic BLE reconnect retry with backoff for transient timeout errors (`br-connection-timeout`). diff --git a/fichero_printer/config.yaml b/fichero_printer/config.yaml index f9774b2..5286365 100644 --- a/fichero_printer/config.yaml +++ b/fichero_printer/config.yaml @@ -1,5 +1,5 @@ name: "Fichero Printer" -version: "0.1.10" +version: "0.1.11" slug: "fichero_printer" description: "REST API for the Fichero D11s (AiYin) thermal label printer over Bluetooth" url: "https://git.leuschner.dev/Tobias/Fichero" diff --git a/fichero_printer/fichero/printer.py b/fichero_printer/fichero/printer.py index 0773645..821b492 100644 --- a/fichero_printer/fichero/printer.py +++ b/fichero_printer/fichero/printer.py @@ -419,6 +419,12 @@ async def connect( await pc.start() yield pc return + except asyncio.TimeoutError as exc: + last_exc = exc + if attempt < BLE_CONNECT_RETRIES: + await asyncio.sleep(BLE_CONNECT_BACKOFF * attempt) + continue + raise PrinterError(f"BLE connection timed out: {exc}") from exc except BleakDBusError as exc: msg = str(exc).lower() if "br-connection-not-supported" in msg: diff --git a/pyproject.toml b/pyproject.toml index 7ae7e1d..804cde7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "fichero-printer" -version = "0.1.10" +version = "0.1.11" description = "Fichero D11s thermal label printer - BLE CLI tool" requires-python = ">=3.10" dependencies = [