Skip to content
This repository has been archived by the owner on Aug 30, 2022. It is now read-only.

Improve stacktrace on connection loss for bluetooth request #49

Merged
merged 6 commits into from
Apr 11, 2020

Conversation

twyatt
Copy link
Member

@twyatt twyatt commented Apr 10, 2020

Rethrow ConnectionLost from CoroutinesGatt.performBluetoothAction to provide more informative stacktrace.

Before

    com.juul.able.gatt.ConnectionLost
        at com.juul.able.gatt.GattCallback.onDisconnecting(GattCallback.kt:39)
        at com.juul.able.gatt.GattCallback.close(GattCallback.kt:45)
        at com.juul.able.gatt.GattCallback.onConnectionStateChange(GattCallback.kt:65)
        at android.bluetooth.BluetoothGatt$1$4.run(BluetoothGatt.java:272)
        at android.bluetooth.BluetoothGatt.runOrQueueCallback(BluetoothGatt.java:780)
        at android.bluetooth.BluetoothGatt.access$200(BluetoothGatt.java:41)
        at android.bluetooth.BluetoothGatt$1.onClientConnectionState(BluetoothGatt.java:267)
        at android.bluetooth.IBluetoothGattCallback$Stub.onTransact(IBluetoothGattCallback.java:192)
        at android.os.Binder.execTransactInternal(Binder.java:1021)
        at android.os.Binder.execTransact(Binder.java:994)

After

    com.juul.able.gatt.GattResponseFailure: Failed to receive response for discoverServices
        at com.juul.able.gatt.CoroutinesGatt.discoverServices(CoroutinesGatt.kt:186)
        at com.juul.able.gatt.CoroutinesGatt$discoverServices$1.invokeSuspend(Unknown Source:11)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:55)
        at android.os.Handler.handleCallback(Handler.java:883)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7356)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
     Caused by: com.juul.able.gatt.ConnectionLost
        at com.juul.able.gatt.GattCallback.onDisconnecting(GattCallback.kt:39)
        at com.juul.able.gatt.GattCallback.close(GattCallback.kt:45)
        at com.juul.able.gatt.GattCallback.onConnectionStateChange(GattCallback.kt:65)
        at android.bluetooth.BluetoothGatt$1$4.run(BluetoothGatt.java:272)
        at android.bluetooth.BluetoothGatt.runOrQueueCallback(BluetoothGatt.java:780)
        at android.bluetooth.BluetoothGatt.access$200(BluetoothGatt.java:41)
        at android.bluetooth.BluetoothGatt$1.onClientConnectionState(BluetoothGatt.java:267)
        at android.bluetooth.IBluetoothGattCallback$Stub.onTransact(IBluetoothGattCallback.java:192)
        at android.os.Binder.execTransactInternal(Binder.java:1021)
        at android.os.Binder.execTransact(Binder.java:994)

Rethrow `ConnectionLost` from `CoroutinesGatt.performBluetoothAction` to
provide more informative stacktrace.

## Before

```java
    com.juul.able.gatt.ConnectionLost
        at com.juul.able.gatt.GattCallback.onDisconnecting(GattCallback.kt:39)
        at com.juul.able.gatt.GattCallback.close(GattCallback.kt:45)
        at com.juul.able.gatt.GattCallback.onConnectionStateChange(GattCallback.kt:65)
        at android.bluetooth.BluetoothGatt$1$4.run(BluetoothGatt.java:272)
        at android.bluetooth.BluetoothGatt.runOrQueueCallback(BluetoothGatt.java:780)
        at android.bluetooth.BluetoothGatt.access$200(BluetoothGatt.java:41)
        at android.bluetooth.BluetoothGatt$1.onClientConnectionState(BluetoothGatt.java:267)
        at android.bluetooth.IBluetoothGattCallback$Stub.onTransact(IBluetoothGattCallback.java:192)
        at android.os.Binder.execTransactInternal(Binder.java:1021)
        at android.os.Binder.execTransact(Binder.java:994)
```

## After

```java
    com.juul.able.gatt.GattResponseFailure: Failed to receive response for discoverServices
        at com.juul.able.gatt.CoroutinesGatt.discoverServices(CoroutinesGatt.kt:186)
        at com.juul.able.gatt.CoroutinesGatt$discoverServices$1.invokeSuspend(Unknown Source:11)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:55)
        at android.os.Handler.handleCallback(Handler.java:883)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7356)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
     Caused by: com.juul.able.gatt.ConnectionLost
        at com.juul.able.gatt.GattCallback.onDisconnecting(GattCallback.kt:39)
        at com.juul.able.gatt.GattCallback.close(GattCallback.kt:45)
        at com.juul.able.gatt.GattCallback.onConnectionStateChange(GattCallback.kt:65)
        at android.bluetooth.BluetoothGatt$1$4.run(BluetoothGatt.java:272)
        at android.bluetooth.BluetoothGatt.runOrQueueCallback(BluetoothGatt.java:780)
        at android.bluetooth.BluetoothGatt.access$200(BluetoothGatt.java:41)
        at android.bluetooth.BluetoothGatt$1.onClientConnectionState(BluetoothGatt.java:267)
        at android.bluetooth.IBluetoothGattCallback$Stub.onTransact(IBluetoothGattCallback.java:192)
        at android.os.Binder.execTransactInternal(Binder.java:1021)
        at android.os.Binder.execTransact(Binder.java:994)
```
@twyatt twyatt changed the title Improve stacktrace for connection loss during bluetooth request Improve stacktrace on connection loss for bluetooth request Apr 10, 2020
@codecov
Copy link

codecov bot commented Apr 10, 2020

Codecov Report

Merging #49 into develop will decrease coverage by 0.91%.
The diff coverage is 33.33%.

Impacted file tree graph

@@              Coverage Diff              @@
##             develop      #49      +/-   ##
=============================================
- Coverage      74.38%   73.46%   -0.92%     
- Complexity        35       36       +1     
=============================================
  Files             14       14              
  Lines            242      245       +3     
  Branches          28       28              
=============================================
  Hits             180      180              
- Misses            52       55       +3     
  Partials          10       10              
Impacted Files Coverage Δ Complexity Δ
core/src/main/java/gatt/CoroutinesGatt.kt 47.36% <33.33%> (-4.07%) 9.00 <0.00> (+1.00) ⬇️

@twyatt twyatt marked this pull request as ready for review April 10, 2020 08:20
@twyatt twyatt added this to the 1.0.0 milestone Apr 10, 2020
@twyatt twyatt merged commit 2e3b20e into develop Apr 11, 2020
@twyatt twyatt deleted the twyatt/GattResponseFailure branch April 11, 2020 19:27
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants