Skip to content

fix: replace force-unwraps in TextDecoder with guard statements#421

Closed
William-Laverty wants to merge 1 commit intoargmaxinc:mainfrom
William-Laverty:fix/text-decoder-force-unwrap-crashes
Closed

fix: replace force-unwraps in TextDecoder with guard statements#421
William-Laverty wants to merge 1 commit intoargmaxinc:mainfrom
William-Laverty:fix/text-decoder-force-unwrap-crashes

Conversation

@William-Laverty
Copy link

Summary

Replaces three force-unwraps in TextDecoder.decodeText that cause EXC_BREAKPOINT crashes during rapid repeated transcription calls (e.g., live transcription preview at ~200ms intervals).

Changes

Location Before After
Line 747 decoderInputs.initialPrompt.last! guard let + throw WhisperError.decodingFailed
Line 683 decoderOutput.logits! (language detection) guard let + throw WhisperError.decodingLogitsFailed
Line 829 decoderOutput.logits! (token decoding) guard let + throw WhisperError.decodingLogitsFailed

All three now throw descriptive WhisperError cases that already exist in the codebase, allowing callers to handle the error gracefully instead of crashing.

Context

During sustained rapid transcription calls (5-10/sec for live preview), decoder state can degrade and hit these nil/empty conditions. The force-unwraps cause hard crashes instead of recoverable errors.

Fixes #414

Replace three force-unwraps in TextDecoder.decodeText that cause crashes
during rapid repeated transcription (e.g., live transcription preview):

1. decoderInputs.initialPrompt.last! (line 747) — crashes if prompt is empty
2. decoderOutput.logits! (line 683) — crashes if logits nil during language detection
3. decoderOutput.logits! (line 829) — crashes if logits nil during token decoding

Now throws descriptive WhisperError instead of crashing, allowing callers
to handle the error gracefully.

Fixes argmaxinc#414
@ZachNagengast
Copy link
Contributor

Little confused why this was opened, it looks like you already have a PR open here with the same diff? #417

@William-Laverty
Copy link
Author

Apologies for the duplicate — this is the same change as #417. Closing this one.

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

2 participants