From d97db702f788afcbbe426ae2a236343a620899c1 Mon Sep 17 00:00:00 2001 From: Koda Date: Sat, 21 Mar 2026 23:33:13 +0000 Subject: [PATCH] fix: handle disconnect during device info read phase The disconnect handler didn't account for awaitingDeviceInfoForProvisioning state, causing it to fall through to the generic "Unexpected disconnect" error. Since the MAC address read is optional (timeout already skips it), this disconnect is now caught explicitly with a clear retriable message. Co-Authored-By: Claude Opus 4.6 (1M context) --- PayfritBeacon/BeaconProvisioner.swift | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/PayfritBeacon/BeaconProvisioner.swift b/PayfritBeacon/BeaconProvisioner.swift index 420a846..59959c5 100644 --- a/PayfritBeacon/BeaconProvisioner.swift +++ b/PayfritBeacon/BeaconProvisioner.swift @@ -980,6 +980,13 @@ extension BeaconProvisioner: CBCentralManagerDelegate { // This is expected behavior, treat as success DebugLog.shared.log("BLE: Disconnect after SaveConfig (idx=\(dxSmartWriteIndex)/\(dxSmartCommandQueue.count)) — treating as success") succeed() + } else if awaitingDeviceInfoForProvisioning { + // Disconnect during device info read (MAC query) — MAC is optional, + // so this is non-critical. Clear the flag and fail gracefully with a + // retriable error instead of the generic "Unexpected disconnect". + DebugLog.shared.log("BLE: Disconnect during device info read — MAC is optional, treating as retriable") + awaitingDeviceInfoForProvisioning = false + fail("Disconnected while reading device info — please retry", code: .disconnected) } else { DebugLog.shared.log("BLE: UNEXPECTED disconnect — state=\(state) writeIdx=\(dxSmartWriteIndex) queueCount=\(dxSmartCommandQueue.count)") fail("Unexpected disconnect", code: .disconnected)