fix(audio): report and handle capture/session startup failures#49
Merged
Conversation
Change startCaptureWithAudioCallback: return type from void to BOOL so callers can detect failure. On failure, trigger handleAudioCaptureError to end the Rust session, reset UI state, and notify the user instead of silently producing no audio.
endSession only closes the audio channel, letting the session process the empty input and emit a spurious "no speech recognized" error. cancelSession sets the cancelled flag so the session aborts cleanly without producing a duplicate error notification.
- Guard error UI state with showingError flag so Rust-side cancelled/idle state changes do not overwrite the 2-second error display - Return BOOL from beginSessionWithMode: and abort early if the Rust session fails to start, instead of proceeding to audio capture - Check startAndReturnError: return value instead of relying on NSError being non-nil
- Clear showingError when a new session starts (hold/tap), so the flag never gets stuck permanently if the user retries within the 2-second error window - Apply the same showingError guard to rustBridgeDidEncounterError so Rust-side failed/idle state changes don't overwrite the error display
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.
Summary
When audio capture failed to start (e.g. device disconnection, format incompatibility), the app silently continued with the UI stuck in "recording" state and a Rust session waiting for audio that would never arrive. The user would eventually see a delayed "no speech recognized" error with no indication of the actual cause.
Return value propagation:
startCaptureWithAudioCallback:now returnsBOOLinstead ofvoid; callers check the result and callhandleAudioCaptureError:on failurebeginSessionWithMode:now returnsBOOL; callers abort before starting audio capture if the Rust session fails to createstartAndReturnError:result is checked directly instead of relying onNSErrorbeing non-nilSession cleanup:
handleAudioCaptureError:usescancelSessioninstead ofendSession—endSessiononly closes the audio channel, letting the session process empty input and emit a spurious "no speech recognized" error;cancelSessionsets the cancelled flag so the session aborts cleanlyError display protection:
showingErrorflag to prevent Rust-side state changes (cancelled,idle,failed) from overwriting the 2-second error display in bothhandleAudioCaptureError:andrustBridgeDidEncounterError:Test plan
xcodebuildpasses