From 9e5603dc290267ff61c37ceab0ea2ccfc7eeeaa0 Mon Sep 17 00:00:00 2001 From: Foti Dim Date: Sun, 18 Jan 2026 22:05:01 +0100 Subject: [PATCH] Enhance error logging in Bluetooth peripheral updates - Added logic to differentiate between read and notify/indicate errors in the `didUpdateValueFor` method of `UniversalBlePlugin`. - Improved error handling by preventing duplicate logging for read operations while maintaining appropriate logging for notify/indicate errors. --- darwin/Classes/UniversalBlePlugin.swift | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/darwin/Classes/UniversalBlePlugin.swift b/darwin/Classes/UniversalBlePlugin.swift index 477ace0..cd5c19a 100644 --- a/darwin/Classes/UniversalBlePlugin.swift +++ b/darwin/Classes/UniversalBlePlugin.swift @@ -559,8 +559,20 @@ private class BleCentralDarwin: NSObject, UniversalBlePlatformChannel, CBCentral } public func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?) { + // Check if this is a read operation first + let isReadOperation = characteristicReadFutures.contains { future in + future.deviceId == peripheral.uuid.uuidString && future.characteristicId == characteristic.uuid.uuidStr && future.serviceId == characteristic.service?.uuid.uuidStr + } + + // Log error appropriately based on operation type if let error { - UniversalBleLogger.shared.logError("NOTIFY_ERROR <- \(peripheral.uuid.uuidString) \(characteristic.uuid.uuidStr): \(error.localizedDescription)") + if isReadOperation { + // This is a read error, but we'll log it in the read future handler below + // to avoid duplicate logging + } else { + // This is a notify/indicate error + UniversalBleLogger.shared.logError("NOTIFY_ERROR <- \(peripheral.uuid.uuidString) \(characteristic.uuid.uuidStr): \(error.localizedDescription)") + } } if characteristic.isNotifying, let characteristicValue = characteristic.value {