Skip to content

feat(flutter): Unhandled Flutter errors do not mark sessions as crashed but unhandled instead - #4007

Merged
buenaflor merged 1 commit into
chore/update-native-sdksfrom
feat/3300-unhandled-session-status
Sep 7, 2026
Merged

buenaflor merged 1 commit into
chore/update-native-sdksfrom
feat/3300-unhandled-session-status

Conversation

@buenaflor

@buenaflor buenaflor commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

📜 Description

Capture Dart and Flutter envelopes through the Android and Cocoa non-terminating envelope APIs.

Unhandled framework errors now keep the current native session running with the same session ID. The native SDK finalizes that session as unhandled when it ends gracefully, while a later real crash still takes precedence as crashed.

Stacked on #4006, which provides Sentry Android 8.55.0, Sentry Cocoa 9.27.0, and the generated JNI API.

Fixes #3300

💡 Motivation and Context

Flutter can continue running after an unhandled framework error. Treating that error as a terminating native crash ends the session and starts a replacement, skewing crash-free session metrics.

💚 How did you test it?

  • Added transport, method-channel, and Android worker regression coverage
  • Ran 99 focused transport/channel/worker tests
  • Ran 28 additional affected Flutter/native tests
  • Passed Flutter analysis with fatal warnings
  • Verified Dart 3.13 formatting

The Android release APK build passed during final stack verification.

📝 Checklist

  • I reviewed submitted code
  • I added tests to verify changes
  • No new PII added or SDK only sends newly added PII if sendDefaultPii is enabled
  • I updated the docs if needed
  • All focused tests passing
  • Public API changes reviewed by another Mobile SDK team member or implemented according to the develop docs spec
  • No breaking changes

🔮 Next steps

Follow-up stacked PR: update native sessions for sampled-out unhandled errors (#3786).

Made with Cursor

@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

🚨 Detected changes in high risk code 🚨

High-risk code has higher potential to break the SDK and may be hard to test. To prevent severe bugs, apply the rollout process for releasing such changes and be extra careful when changing and reviewing these files:

  • packages/flutter/darwin/sentry_flutter/Sources/sentry_flutter/SentryFlutterPlugin.swift

@github-actions

github-actions Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Semver Impact of This PR

⚪ None (no version bump detected)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


No changelog entries will be generated from this PR.


🤖 This preview updates automatically when you update the PR.

@codecov

codecov Bot commented Sep 7, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.00%. Comparing base (5686a10) to head (f5c4787).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@                     Coverage Diff                      @@
##           chore/update-native-sdks    #4007      +/-   ##
============================================================
- Coverage                     93.00%   93.00%   -0.01%     
============================================================
  Files                           111      111              
  Lines                          4347     4346       -1     
============================================================
- Hits                           4043     4042       -1     
  Misses                          304      304              
Flag Coverage Δ
sentry_firebase_remote_config 100.00% <ø> (ø)
sentry_flutter 92.70% <100.00%> (-0.01%) ⬇️
sentry_supabase 97.48% <ø> (ø)

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 marked this pull request as ready for review September 7, 2026 11:17
@buenaflor
buenaflor requested a review from denrase as a code owner September 7, 2026 11:17
Copilot AI lite review requested due to automatic review settings September 7, 2026 11:17

Copilot AI 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.

🟡 Changes recommended

The Cocoa plugin’s captureEnvelope guard should also validate empty envelope data to match its error messaging and avoid misleading/incorrect failure behavior.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR updates the Flutter SDK’s native envelope forwarding so Dart/Flutter envelopes are captured via the non-terminating native envelope APIs (Android JNI + Cocoa), which is a prerequisite for keeping the current native session alive after non-fatal “unhandled” framework errors (per #3300).

Changes:

  • Removes the containsUnhandledException boolean from the SentryNativeBinding.captureEnvelope API and updates callers/tests accordingly.
  • Android: routes worker capture through InternalSentrySdk.captureEnvelopeNonTerminating(...) and simplifies worker messaging to only carry envelope bytes.
  • iOS/macOS: changes the method-channel payload to pass Uint8List directly and switches the plugin to captureNonTerminating(...).

Standards

  • No standards violations found in the provided diff hunks; the API simplification is confined to lib/src and the only surfaced accessor to SentryNativeBinding is annotated @internal (so this should not be treated as a public API break).
  • Test updates appear consistent with the signature and channel payload changes.

Standards summary: 0 findings; worst issue: n/a.

Spec

  • The diff aligns with the PR description/issue requirements to use Android/Cocoa non-terminating envelope capture APIs instead of treating forwarded unhandled errors as process-terminating crashes.
  • No obvious scope creep in the shown hunks.

Spec summary: 0 findings; worst issue: n/a.

Correctness

  • One correctness/UX issue in the Cocoa plugin: the guard’s error message claims “null or empty” but previously only validated “null”; this can make failures misleading and can shift an “empty envelope” into the “cannot parse envelope” error path. (A concrete fix was provided as a PR comment.)

Correctness summary: 1 finding; worst issue: misleading/insufficient guard in captureEnvelope for empty payloads.

File summaries
File Description
packages/flutter/lib/src/native/sentry_native_binding.dart Simplifies captureEnvelope signature (drops unhandled flag).
packages/flutter/lib/src/file_system_transport.dart Forwards envelopes to native without passing an unhandled flag.
packages/flutter/lib/src/native/java/android_core_worker.dart Sends only envelope bytes to the worker and captures via non-terminating Android JNI API.
packages/flutter/lib/src/native/sentry_native_channel.dart Changes iOS/macOS method-channel invocation to pass bytes directly (not a list).
packages/flutter/darwin/sentry_flutter/Sources/sentry_flutter/SentryFlutterPlugin.swift Updates method-channel decoding and uses non-terminating Cocoa envelope capture API.
packages/flutter/lib/src/native/java/sentry_native_java.dart Forwards envelope bytes to the Android worker without a flag.
packages/flutter/lib/src/web/sentry_web.dart Updates web binding to new captureEnvelope signature.
packages/flutter/lib/src/native/c/sentry_native.dart Updates unsupported FFI binding to new captureEnvelope signature.
packages/flutter/test/** Updates mocks and tests for the signature and method-channel argument shape changes.
Review details
  • Files reviewed: 16/16 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Capture Dart and Flutter envelopes through the native non-terminating APIs so unhandled errors keep the active session alive and finalize it with the unhandled status.

Fixes #3300

Co-Authored-By: Cursor <cursor@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@buenaflor
buenaflor force-pushed the feat/3300-unhandled-session-status branch from 107b47f to f5c4787 Compare September 7, 2026 14:25
@buenaflor
buenaflor merged commit 33f23fc into v10-branch Sep 7, 2026
59 of 66 checks passed
@buenaflor
buenaflor deleted the feat/3300-unhandled-session-status branch September 7, 2026 14:26
@buenaflor buenaflor changed the title feat(flutter): Track unhandled sessions feat(flutter): Unhandled Flutter errors do not mark sessions as crashed but unhandled instead Sep 8, 2026
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.

3 participants