Skip to content

fix(flutter): Prevent StateError when delayed frames list is empty#3876

Merged
buenaflor merged 4 commits into
getsentry:mainfrom
muhammadkamel:fix/delayed-frames-empty-state
Jul 13, 2026
Merged

fix(flutter): Prevent StateError when delayed frames list is empty#3876
buenaflor merged 4 commits into
getsentry:mainfrom
muhammadkamel:fix/delayed-frames-empty-state

Conversation

@muhammadkamel

@muhammadkamel muhammadkamel commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Description

This PR fixes a crash in delayed frames tracking when _delayedFrames becomes empty after filtering in removeIrrelevantFrames.

What changed

  • Replaced .first with .firstOrNull when reading _delayedFrames
  • Kept _oldestFrameEndTimestamp as null when no delayed frames remain

Why

Calling .first on an empty list can throw:
StateError (Bad state: No element)
Screenshot 2026-07-12 at 7 22 04 PM

@buenaflor buenaflor left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. we've had this report before that VSCode catches this error, this doesn't cause any production issues since it only happens with VSCode but we should nonetheless update it with firstOrNull 👍

@codecov

codecov Bot commented Jul 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.87%. Comparing base (3d4953b) to head (7c405b9).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3876      +/-   ##
==========================================
+ Coverage   87.46%   91.87%   +4.41%     
==========================================
  Files         338      105     -233     
  Lines       12283     3802    -8481     
==========================================
- Hits        10743     3493    -7250     
+ Misses       1540      309    -1231     
Flag Coverage Δ
sentry ?
sentry_dio ?
sentry_drift ?
sentry_file ?
sentry_firebase_remote_config 100.00% <ø> (ø)
sentry_flutter 91.49% <100.00%> (+0.02%) ⬆️
sentry_grpc ?
sentry_hive ?
sentry_isar ?
sentry_link ?
sentry_logging ?
sentry_sqflite ?
sentry_supabase 97.27% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@buenaflor
buenaflor merged commit 3d92f3c into getsentry:main Jul 13, 2026
54 of 59 checks passed
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.

2 participants