innoveit / react-native-ble-manager

React Native BLE communication module
http://innoveit.github.io/react-native-ble-manager/
Apache License 2.0
2.13k stars 768 forks source link

[FIX] errors were ignored due to broken serialization in read() #1251

Closed weese closed 3 months ago

weese commented 3 months ago

That bug was a tricky one. I was wondering why I couldn't properly detect iOS errors like Authentication is insufficient. or Encryption is insufficient. which happen after "forgetting" a BLE device and then trying to read a characteristic. Even when wrapping a try ... catch block around a read() call, read() only returned a null buffer instead of throwing an error.

It took me a while to find the underlying problem which is an NSError occurring in peripheral(_:didUpdateValueFor:error:) directly being passed as argument for RCTResponseSenderBlock although it is not a standard JSON type. As a result, on the Javascript-side of React Native the NSError was swallowed and came out as null, which was interpreted as no error at all with a null array.

I fixed all places where the error was directly passed and now read() correctly throws an error as expected in my code.

I think this also fixes at least this issue I found during debugging: https://github.com/innoveit/react-native-ble-manager/issues/590

weese commented 1 month ago

@marcosinigaglia Thanks for merging. Do you plan a new patch/minor release any time soon? We then could in our code refer to this official repo again.

marcosinigaglia commented 1 month ago

Is published now.