test: Add tests to demonstrate withScope
data loss for uncaught errors
#11204
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds integration tests (browser and node) to demonstrate the current behavior around loosing scope data when a thrown error is caught by global handlers "outside" the lifetime of the throw origin's scope. This occurs specifically within the
withScope
API where the scope is popped if an error is caught but then the error is rethrown to be caught by handlers down the line.This behaviour was reported in #11133 and investigated across SDKs in getsentry/sentry-python#2857. For now it seems that general consensus is that this is expected behaviour.
So in an effort to be aware of the implications of this behavior (i.e. somewhat unexpected scope data loss), let's add these tests.
Side note: In the vast majority of our integration tests, we call
captureException
; Hence, we rarely test how unhandled errors caught by our global error handler instrumentations behave (or potentially differ from a manually captured error). We should capture errors more diversely in the future.