Skip to content
This repository was archived by the owner on Feb 19, 2024. It is now read-only.
This repository was archived by the owner on Feb 19, 2024. It is now read-only.

Unhandled KeyError Exception #204

@labishrestha2

Description

@labishrestha2

In ble_adapter.py, there are several spots where the dict values are accessed without checking if they exist, that causes KeyErrors.

For e.g. in ble_adapter.py : 272:

 @NordicSemiErrorCheck(expected=BLEGattStatusCode.success)
    def service_discovery(self, conn_handle, uuid=None):
        vendor_services = []
        self.driver.ble_gattc_prim_srvc_disc(conn_handle, uuid, 0x0001)

        while True:
            response = self.evt_sync[conn_handle].wait(  # Here sometimes, the conn_handle could not be in the evt_sync dict
                evt=BLEEvtID.gattc_evt_prim_srvc_disc_rsp
            )

            if response["status"] == BLEGattStatusCode.success: # Here the response can be None, or it may not contain "status"
                for s in response["services"]:
                    if s.uuid.value == BLEUUID.Standard.unknown:

I've found that every now and then the BLE service discovery will fail because of a KeyError here or sometimes a None response is returned. Adding a Key check and None check here seems to fix most of the disconnections during discovery.

I'll go ahead and submit PR with my changes. Feel free to iterate.

Thank you

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions