Repository navigation
feat(flutter): Unhandled Flutter errors do not mark sessions as crashed but unhandled instead - #4007
Conversation
🚨 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:
|
Semver Impact of This PR⚪ None (no version bump detected) 📋 Changelog PreviewThis is how your changes will appear in the changelog. No changelog entries will be generated from this PR. 🤖 This preview updates automatically when you update the PR. |
Codecov Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
There was a problem hiding this comment.
🟡 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
containsUnhandledExceptionboolean from theSentryNativeBinding.captureEnvelopeAPI 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
Uint8Listdirectly and switches the plugin tocaptureNonTerminating(...).
Standards
- No standards violations found in the provided diff hunks; the API simplification is confined to
lib/srcand the only surfaced accessor toSentryNativeBindingis 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.
887fa2d to
107b47f
Compare
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>
107b47f to
f5c4787
Compare
📜 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
unhandledwhen it ends gracefully, while a later real crash still takes precedence ascrashed.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?
The Android release APK build passed during final stack verification.
📝 Checklist
sendDefaultPiiis enabled🔮 Next steps
Follow-up stacked PR: update native sessions for sampled-out unhandled errors (#3786).
Made with Cursor