Skip to content

Commit

Permalink
Dematerialize exceptions inside readCharacteristic instead of in some…
Browse files Browse the repository at this point in the history
… 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.
  • Loading branch information
Sander Kersten committed Feb 7, 2025
1 parent 9d7f0a0 commit 54e1c9f
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,19 @@ class ConnectedDeviceOperationImpl implements ConnectedDeviceOperation {
_blePlatform.charValueUpdateStream;

@override
Future<List<int>> readCharacteristic(CharacteristicInstance characteristic) {
Future<List<int>> 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
Expand Down

0 comments on commit 54e1c9f

Please sign in to comment.