Fix BLEConnection AttributeError on disconnect handler setup#4
Conversation
Co-authored-by: rgregg <[email protected]>
|
@copilot is this something different about linux vs. mac? It seems like the other code worked fine on a Mac. Do we need to special case this based on platform? |
No, this is not platform-specific. The meshcore library (v2.2.5) uses The original code had fallback logic that should have worked on both platforms: disconnect_setter = getattr(connection, "set_disconnect_handler", None)
if callable(disconnect_setter): # Would be False with real BLEConnection
disconnect_setter(handler)
else:
callback_setter = getattr(connection, "set_disconnect_callback", None)
callback_setter(handler) # Would execute with real BLEConnectionHowever, the test mock incorrectly used The fix removes the unnecessary fallback and uses the actual meshcore API directly. No platform-specific code needed. (c16b656) |
There was a problem hiding this comment.
Pull request overview
This PR fixes a critical bug where the proxy crashes on BLE connection due to attempting to call a non-existent method. The code incorrectly tried set_disconnect_handler() first with a fallback to set_disconnect_callback(), but meshcore's BLEConnection and SerialConnection only expose set_disconnect_callback().
Changes:
- Removed fallback logic attempting the non-existent
set_disconnect_handler()method - Direct call to
set_disconnect_callback()for both connection types - Updated test mock to match actual meshcore API
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/meshcore_proxy/proxy.py | Simplified disconnect callback setup by directly calling the correct API method |
| tests/test_proxy.py | Updated MockRadio to use set_disconnect_callback instead of set_disconnect_handler |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
The proxy crashes on BLE connection with
'BLEConnection' object has no attribute 'set_disconnect_handler'. The code attempted to call a non-existent method - meshcore'sBLEConnectionandSerialConnectiononly exposeset_disconnect_callback().Changes:
set_disconnect_handler()set_disconnect_callback()for both connection typesOriginal prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.