Repository navigation
fix: preserve chained error handlers across restarts - #624
Conversation
|
[Medium risk] Fixes error handler lifecycle to preserve chaining across restarts. The PR appears safe to merge; no actionable regression was identified. Reviews (1) · Last reviewed commit: "fix: preserve chained error handlers acr..." |
posthog-flutter Compliance ReportDate: 2026-09-30 15:02:29 UTC ✅ All Tests Passed!45/45 tests passed Capture Tests✅ 29/29 tests passed View Details
Feature_Flags Tests✅ 16/16 tests passed View Details
|
|
found while reviewing #621 but the issue was already there |
turnipdabeets
left a comment
There was a problem hiding this comment.
Verified locally: with main's implementation the new lifecycle file fails 10 of 14 (upstream dropped after uninstall, retained handler still capturing, double capture after reinstall, recursion on restart), and all 14 pass at da957dba. The per-install closure with its own delegate matches what Android does with its dormant pass-through, and nothing public changes.
One nit, not blocking: _isEnabled && is redundant next to the identical(...) check, since stop() nulls the field.
Approving. #629 can go in after this, and #621 will need a rebase on the same file.
|
@turnipdabeets Removed the redundant |
💡 Motivation and Context
When another error handler wraps PostHog's handler, disabling or closing the SDK leaves that wrapper holding our old callback. Teardown clears the callback's upstream delegate but does not stop it from capturing. The original handler no longer runs, and enabling or setting up the SDK again can capture the same error twice.
Each installed Flutter and platform error callback now keeps its own upstream delegate. Retained callbacks only forward after teardown. Only the current callback can capture after a restart, which also prevents circular chains when the same integration is stopped and started. Callback identity is the only capture guard, since teardown clears the stored callback references. Platform handlers keep the upstream handled result and return false when there is no upstream handler.
This follows the wrapper lifecycle described in the consent-gating spec and the integration teardown behavior in the shutdown spec. There are no public API changes or deviations in the behavior this fix touches.
💚 How did you test it?
make checkFormatDart,make analyzeDart,make checkApiDart, andgit diff --check.9f0fc6fafter removing the redundant enabled checks.Native example builds were not run locally. CI covers those builds.
📝 Checklist
If releasing new changes
🤖 Agent context
Autonomy: Human-driven (agent-assisted)
Investigated and fixed with Pi, using Git, Flutter/Dart, GitHub CLI, and isolated autoreview. The work stayed in a dedicated worktree. The fix uses per-install callback delegates and callback identity rather than event deduplication, so it preserves the handler chain without changing exception processing.