Skip to content

fix: replace force-unwraps in TextDecoder with safe error handling#420

Open
claudeaceae wants to merge 1 commit intoargmaxinc:mainfrom
claudeaceae:fix/safe-unwrap-text-decoder
Open

fix: replace force-unwraps in TextDecoder with safe error handling#420
claudeaceae wants to merge 1 commit intoargmaxinc:mainfrom
claudeaceae:fix/safe-unwrap-text-decoder

Conversation

@claudeaceae
Copy link
Copy Markdown

Summary

  • Replace 6 force-unwrap operations in TextDecoder.swift that crash during sustained rapid transcription
  • decoderOutput.logits!guard let with WhisperError.decodingLogitsFailed (2 sites: detectLanguage and decodeText)
  • decoderInputs.initialPrompt.last!guard let with WhisperError.prepareDecoderInputsFailed
  • sampleResult.tokens.last!guard let with WhisperError.decodingFailed (2 sites)
  • sampleResult.logProbs.last!guard let with WhisperError.decodingFailed

All replacements use existing WhisperError cases so callers can catch and handle errors gracefully instead of crashing the app.

Test plan

Fixes #414

🤖 Generated with Claude Code

Replace 6 force-unwrap operations in TextDecoder.swift that can crash
during sustained rapid transcription (e.g., live preview at ~200ms
intervals). The decoder state can degrade over many sequential calls,
causing optional values to be nil where force-unwraps assume non-nil.

Changes:
- decoderOutput.logits! → guard let with WhisperError.decodingLogitsFailed
- initialPrompt.last! → guard let with WhisperError.prepareDecoderInputsFailed
- sampleResult.tokens.last! → guard let with WhisperError.decodingFailed
- sampleResult.logProbs.last! → guard let with WhisperError.decodingFailed

Callers can now catch and handle these errors gracefully instead of
crashing the entire app.

Fixes argmaxinc#414

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TextDecoder.decodeText force-unwraps cause crashes during repeated live transcription

1 participant