-
Notifications
You must be signed in to change notification settings - Fork 1.4k
BleTransport.writeCharacteristic - device not connected crash #4527
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…sconnected Add connection check before attempting BLE write and don't rethrow write errors. BLE write failures (device not connected, GATT_WRITE_REQUEST_BUSY) should log a warning instead of crashing the app. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request effectively addresses a crash issue in BleTransport.writeCharacteristic by adding pre-condition checks and gracefully handling exceptions during BLE write operations. The changes prevent the app from crashing when the device is disconnected, a characteristic is not found, or a write operation fails. My review focuses on improving the logging level for these events to ensure they remain visible for debugging and monitoring purposes, aligning with the intent stated in the pull request description.
| @override | ||
| Future<void> writeCharacteristic(String serviceUuid, String characteristicUuid, List<int> data) async { | ||
| if (!_bleDevice.isConnected) { | ||
| Logger.debug('BLE Transport: Cannot write characteristic - device not connected'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pull request description mentions "Log warning instead of throwing exception", but Logger.debug is used here. Using Logger.warning would be more appropriate to ensure these events are visible in production logs, as debug logs are often compiled out. An attempt to write to a disconnected device might indicate a logic error in the calling code that should be investigated.
| Logger.debug('BLE Transport: Cannot write characteristic - device not connected'); | |
| Logger.warning('BLE Transport: Cannot write characteristic - device not connected'); |
| final characteristic = await _getCharacteristic(serviceUuid, characteristicUuid); | ||
| if (characteristic == null) { | ||
| throw Exception('Characteristic not found: $serviceUuid:$characteristicUuid'); | ||
| Logger.debug('BLE Transport: Characteristic not found: $serviceUuid:$characteristicUuid'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This case, where a characteristic is not found, was previously throwing an exception. Downgrading it to a debug log might hide important issues like firmware mismatches or incorrect UUIDs. Consistent with the PR's goal to "Log warning", using Logger.warning would provide better visibility into these potential configuration errors.
| Logger.debug('BLE Transport: Characteristic not found: $serviceUuid:$characteristicUuid'); | |
| Logger.warning('BLE Transport: Characteristic not found: $serviceUuid:$characteristicUuid'); |
| @@ -195,7 +201,8 @@ class BleTransport extends DeviceTransport { | |||
| await characteristic.write(data, allowLongWrite: needsLongWrite); | |||
| } catch (e) { | |||
| Logger.debug('BLE Transport: Failed to write characteristic: $e'); | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As stated in the pull request description, write failures should be logged as warnings. Using Logger.debug might cause these failures (like GATT_WRITE_REQUEST_BUSY) to go unnoticed in production environments where debug logs are typically disabled. Changing this to Logger.warning will align with the stated goal and ensure these events are captured for monitoring.
| Logger.debug('BLE Transport: Failed to write characteristic: $e'); | |
| Logger.warning('BLE Transport: Failed to write characteristic: $e'); |
|
Hey @aaravgarg! Thanks for this BLE write crash fix — big impact (900+ events, 192 users). We're tidying up stale PRs — this one has been open 8 days with untested test plan and no demo. The gemini review also raised concerns about using debug-level logging instead of warnings — worth addressing. Could you run the test plan, address the review feedback, and add a brief demo? Feel free to reopen once ready! |
|
Hey @aaravgarg 👋 Thank you so much for taking the time to contribute to Omi! We truly appreciate you putting in the effort to submit this pull request. After careful review, we've decided not to merge this particular PR. Please don't take this personally — we genuinely try to merge as many contributions as possible, but sometimes we have to make tough calls based on:
Your contribution is still valuable to us, and we'd love to see you contribute again in the future! If you'd like feedback on how to improve this PR or want to discuss alternative approaches, please don't hesitate to reach out. Thank you for being part of the Omi community! 💜 |
Summary
Crash Stats
Test plan
🤖 Generated with Claude Code