[DRAFT] Improve stacktrace of manually captured exceptions on iOS #493
+34
−14
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.
Note: this will mess up issue grouping because it changes the stacktrace
📜 Description
Improve stacktrace of manually captured exceptions on iOS - unhandled exceptions already work well
💡 Motivation and Context
On iOS, when calling
captureException()with a KotlinThrowable, the stack trace shows wherecaptureException()was called, not where the exception was instantiated.Example
Expected stack trace:
UserApi.fetchUser()→ ...Actual stack trace:
ErrorHandler.report()→ ...This works correctly on Android, but not on iOS.
Cause
SentrySDK.captureException()in Sentry Cocoa ignores theNSException'scallStackReturnAddresses()and captures a fresh stack trace at call time.Fix
Instead of calling
SentrySDK.captureException(), we now:SentryEventdirectlyNSExceptionusingNSExceptionKt_SentryCrashStackCursorFromNSException()SentrySDK.captureEvent()This is the same approach already used for unhandled exceptions in
SentryUnhandledExceptions.kt(the old way at least).Fixes #341 and #77
💚 How did you test it?
Before:

After:

📝 Checklist
You have to check all boxes before merging:
sendDefaultPIIis enabled.🔮 Next steps