CaptureProvider._processVoiceCommandBytes - Null check crash#4532
CaptureProvider._processVoiceCommandBytes - Null check crash#4532
Conversation
Prevent null check crash when _recordingDevice is null during voice command processing (e.g. device disconnected mid-session). Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Code Review
This pull request addresses a crash in _processVoiceCommandBytes by adding a null check for _recordingDevice before it's accessed. This is a good and necessary fix. I've suggested a small improvement to make the code even more robust by capturing _recordingDevice in a local variable. This avoids using the null-assertion operator (!) and makes the code safer against potential race conditions.
| if (_recordingDevice == null) { | ||
| Logger.debug("_processVoiceCommandBytes: recording device is null, skipping"); | ||
| return; | ||
| } | ||
|
|
||
| BleAudioCodec codec = await _getAudioCodec(_recordingDevice!.id); |
There was a problem hiding this comment.
While adding the null check is a good fix for the crash, it's better to avoid using the null-assertion operator (!) on _recordingDevice. Since _recordingDevice is a mutable class field, the compiler can't guarantee it won't be null after the check, especially with await calls.
A safer approach is to capture _recordingDevice in a local variable. This allows for type promotion and removes the need for the ! operator, making the code more robust against potential race conditions.
final recordingDevice = _recordingDevice;
if (recordingDevice == null) {
Logger.debug("_processVoiceCommandBytes: recording device is null, skipping");
return;
}
BleAudioCodec codec = await _getAudioCodec(recordingDevice.id);Prevents potential null dereference if _recordingDevice becomes null between the null check and the await _getAudioCodec call. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
closed in #4628 |
|
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
_recordingDevicebefore accessing.idin_processVoiceCommandBytesCrash Stats
Test plan
🤖 Generated with Claude Code