aioble: Use DeviceDisconnectedError for disconnected guards.#472
Open
andrewleech wants to merge 1 commit intomicropython:masterfrom
Open
aioble: Use DeviceDisconnectedError for disconnected guards.#472andrewleech wants to merge 1 commit intomicropython:masterfrom
andrewleech wants to merge 1 commit intomicropython:masterfrom
Conversation
6fc995d to
6b7d13a
Compare
6b7d13a to
2117b6f
Compare
2117b6f to
cbe8041
Compare
cbe8041 to
c491981
Compare
7513416 to
021db78
Compare
Replace ValueError("Not connected") with DeviceDisconnectedError in
the is_connected() guards in L2CAPChannel.__init__,
DeviceConnection.exchange_mtu, and Characteristic.indicate. Callers
already catch DeviceDisconnectedError for disconnect handling; the
ValueError was not semantically correct and required string matching
to distinguish from other ValueErrors.
Also make L2CAPDisconnectedError a subclass of DeviceDisconnectedError
so that mid-operation L2CAP disconnections are caught by the same
handler (e.g. in the l2cap_file_server example).
Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
021db78 to
a51c737
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a BLE device disconnects during an L2CAP operation, callers receive a generic
ValueError("Not connected")instead ofDeviceDisconnectedError. This means application code that catchesDeviceDisconnectedErrorto handle disconnection gracefully (as thel2cap_file_serverexample does) cannot distinguish a disconnection from an invalid argument, and theValueErrorpropagates to the top-level exception handler.Similarly,
L2CAPDisconnectedError(raised mid-operation bysend/recvinto/flush) inherits from bareExceptionrather thanDeviceDisconnectedError, so it also escapesexcept DeviceDisconnectedErrorhandlers.This commit:
L2CAPDisconnectedErrora subclass ofDeviceDisconnectedError, so mid-operation L2CAP disconnections are caught by the same handlers that catch device-level disconnections.ValueError("Not connected")with the appropriateDeviceDisconnectedError(or subclass) in theis_connected()guards inL2CAPChannel.__init__,DeviceConnection.exchange_mtu, andCharacteristic.indicate.