From 54e1c9f72963c0fa714c9724ea42cba8d3bda6da Mon Sep 17 00:00:00 2001 From: Sander Kersten Date: Fri, 7 Feb 2025 14:19:22 +0100 Subject: [PATCH] Dematerialize exceptions inside readCharacteristic instead of in some stream transformation so the stack trace is the one for the call to readCharacteristic (ending in the user's code that initiated the read that failed) instead of some generic list of stream handling methods. --- .../lib/src/connected_device_operation.dart | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/flutter_reactive_ble/lib/src/connected_device_operation.dart b/packages/flutter_reactive_ble/lib/src/connected_device_operation.dart index da007bd7..de8eb833 100644 --- a/packages/flutter_reactive_ble/lib/src/connected_device_operation.dart +++ b/packages/flutter_reactive_ble/lib/src/connected_device_operation.dart @@ -43,16 +43,19 @@ class ConnectedDeviceOperationImpl implements ConnectedDeviceOperation { _blePlatform.charValueUpdateStream; @override - Future> readCharacteristic(CharacteristicInstance characteristic) { + Future> readCharacteristic( + CharacteristicInstance characteristic, + ) async { final specificCharacteristicValueStream = characteristicValueStream .where((update) => update.characteristic == characteristic) - .map((update) => update.result.dematerialize()); + .map((update) => update.result); - return _blePlatform + final result = await _blePlatform .readCharacteristic(characteristic) .asyncExpand((_) => specificCharacteristicValueStream) .firstWhere((_) => true, orElse: () => throw NoBleCharacteristicDataReceived()); + return result.dematerialize(); } @override