Skip to content

feat(core): add opt-in loud invariants assertion instrumentation - #6592

Draft
antonis wants to merge 2 commits into
mainfrom
feat/loud-invariants
Draft

feat(core): add opt-in loud invariants assertion instrumentation#6592
antonis wants to merge 2 commits into
mainfrom
feat/loud-invariants

Conversation

@antonis

@antonis antonis commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

📢 Type of change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring

📜 Description

Adds an opt-in Metro/Babel transform that rewrites assertion call sites (invariant, assert, warning, console.assert) so a violated assertion reports a non-fatal Sentry event instead of being stripped from release bundles or crashing with a minified message.

  • Enabled via loudInvariants in the Sentry Metro config; off by default. First-party code is instrumented by default; dependencies are opt-in through an includeNodeModules allowlist.
  • Hard preconditions (invariant/assert) still throw after reporting; warning/console.assert are report-only.
  • New public runtime API captureInvariantViolation() (also usable by hand).
  • Fixes a related gap in the RN global error handler so an error already captured by Sentry and re-thrown isn't reported a second time.

💡 Motivation and Context

Assertions are usually stripped from release builds or, when they do fire, surface as unreadable minified crashes. This surfaces them as grouped, non-fatal Sentry events with the condition, runtime values, and a stack anchored at the assertion site — without changing app source.

💚 How did you test it?

Unit tests for the reporter, the Babel plugin, the transformer wiring, and the RN error handler. Manually verified on the RN sample (iOS): invariant from a dependency, first-party console.assert, and a hand-written call each produced the expected handled events.

📝 Checklist

  • 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.
  • I updated the wizard if needed.
  • All 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

Add an opt-in Metro/Babel transform that rewrites assertion call sites
(invariant, assert, warning, console.assert) so a violated assertion
reports a non-fatal Sentry event instead of being stripped from release
bundles or crashing with a minified message.

Adds the captureInvariantViolation runtime API and fixes a related gap
in the RN global error handler so an already-captured, re-thrown error is
not reported a second time.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@github-actions

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.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor
Fails
🚫 Pull request is not ready for merge, please add the "ready-to-merge" label to the pull request
Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Generated by 🚫 dangerJS against 4aaf8bd

@antonis

antonis commented Aug 17, 2026

Copy link
Copy Markdown
Contributor Author

@cursor review

@antonis

antonis commented Aug 17, 2026

Copy link
Copy Markdown
Contributor Author

@sentry review

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.

1 participant