Skip to content

fix: guard against non-numeric speaker label crashing TranscriptSegment#5386

Open
krushnarout wants to merge 1 commit intomainfrom
fix/transcript-speaker
Open

fix: guard against non-numeric speaker label crashing TranscriptSegment#5386
krushnarout wants to merge 1 commit intomainfrom
fix/transcript-speaker

Conversation

@krushnarout
Copy link
Member

@krushnarout krushnarout commented Mar 5, 2026

Summary

  • Line of Code:

speakerId = speaker != null ? int.parse(speaker!.split('_')[1]) : 0;

  • Cause: speaker from the API can arrive as "SPEAKER_None" (Python's None serialized into a string). int.parse("None") throws a FormatException, crashing the app on conversation load.
  • Fix: Replaced int.parse with int.tryParse(...) ?? 0 and guarded the split index — same pattern already used for start/end in the same file.

🤖 Generated with Claude Code

int.parse throws FormatException when speaker arrives as "SPEAKER_None"
from the backend. Replaced with int.tryParse ?? 0 and added split guard.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@greptile-apps
Copy link

greptile-apps bot commented Mar 5, 2026

Greptile Summary

This PR fixes a FormatException crash in TranscriptSegment's constructor that occurred when the API returned "SPEAKER_None" as a speaker label (Python's None embedded in the speaker string format). The fix replaces int.parse(speaker!.split('_')[1]) with a null-safe split guarded by a length check and int.tryParse(...) ?? 0, matching the defensive approach already used for start/end parsing in fromJson.

  • Bug fixed: "SPEAKER_None" from the API no longer crashes the app with a FormatException on conversation load.
  • Approach: Two-step guard — first checks that split('_') produced at least two parts, then uses int.tryParse to gracefully handle non-numeric suffixes, defaulting to 0.
  • Consistency: The pattern matches how start and end are already parsed in fromJson (lines 81–82), keeping the defensive style uniform across the file.
  • Note: Segments with an unresolvable speaker label (e.g. "SPEAKER_None") are silently assigned speakerId = 0, which is the same ID as a legitimate SPEAKER_00. In conversations that also contain a real SPEAKER_00, those segments will be visually grouped together in the UI — an acceptable trade-off over crashing.

Confidence Score: 5/5

  • This PR is safe to merge — it is a minimal, targeted crash fix with no regressions introduced.
  • The change is a single-line logic fix in a well-understood code path. All edge cases (null speaker, no underscore, numeric suffix, non-numeric suffix like "None") are handled correctly. The pattern is already established in the same file for other fields, and no new logic or dependencies are introduced.
  • No files require special attention.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["TranscriptSegment constructor<br/>called with speaker value"] --> B{"speaker == null?"}
    B -- "Yes" --> E["parts = []"]
    B -- "No" --> C["parts = speaker.split('_')"]
    C --> D{"parts.length > 1?"}
    D -- "No<br/>e.g. 'SPEAKER' or empty" --> F["speakerId = 0"]
    D -- "Yes<br/>e.g. 'SPEAKER_00' or 'SPEAKER_None'" --> G["int.tryParse(parts[1])"]
    G --> H{"Parse succeeded?"}
    H -- "Yes<br/>e.g. parts[1] = '00'" --> I["speakerId = parsed int"]
    H -- "No<br/>e.g. parts[1] = 'None'" --> J["speakerId = 0 (fallback)"]
    E --> F
Loading

Last reviewed commit: 0af437f

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.

FlutterError - FormatException: Invalid radix-10 number (at character 1) None ^

1 participant