Skip to content

Fix missing stack traces for NSException objects reported via NSApplication.shared.reportException(_:) on macOS.#7284

Merged
denrase merged 13 commits intomainfrom
repro/cocoa-287-nsexception-wrong-stacktrace
Feb 3, 2026
Merged

Fix missing stack traces for NSException objects reported via NSApplication.shared.reportException(_:) on macOS.#7284
denrase merged 13 commits intomainfrom
repro/cocoa-287-nsexception-wrong-stacktrace

Conversation

@denrase
Copy link
Copy Markdown
Collaborator

@denrase denrase commented Jan 26, 2026

📜 Description

Fixes missing stack traces for NSException objects reported via NSApplication.shared.reportException(_:) on macOS. When exceptions are reported (not raised), callStackReturnAddresses is empty, resulting in stack traces showing null in Sentry.

In this case, we capture the current thread's stack trace using sentrycrashsc_initSelfThread as a fallback.

This does affect grouping, as these are now detected as new events.

Before
https://sentry-sdks.sentry.io/issues/7219136196/?project=5428557&query=is%3Aunresolved&referrer=issue-stream

After
https://sentry-sdks.sentry.io/issues/7219236592/?project=5428557&query=is%3Aunresolved&referrer=issue-stream

💡 Motivation and Context

NSException.callStackReturnAddresses is only populated when an exception is raised via exception.raise(). When NSApplication.shared.reportException(_:) is used, the exception is passed around without being raised, leaving callStackReturnAddresses empty. This fix mirrors Xcode's crash report behavior by capturing the current thread's stack trace when the exception's stack is unavailable.

Closes #COCOA-287

💚 How did you test it?

Added unit test, run sample app.

📝 Checklist

You have to check all boxes before merging:

  • I added tests to verify the 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.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.

@linear
Copy link
Copy Markdown

linear Bot commented Jan 26, 2026

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jan 26, 2026

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).


Bug Fixes 🐛

  • In_foreground and is_active app context by philipphofmann in #7188

Internal Changes 🔧

Deps

  • Bump getsentry/craft/.github/workflows/changelog-preview.yml from 2.20.0 to 2.20.1 by dependabot in #7344
  • Bump mikepenz/action-junit-report from 6.1.0 to 6.2.0 by dependabot in #7346

Other

  • Update React Native branch to v8 by itaybre in #7356
  • IPhone 16 Pro default in xcodebuild.sh by philipphofmann in #7348
  • Update GA workflow to use reat native branch with v9 by itaybre in #7342
  • ObjC Integration cleanup by itaybre in #7320

Other

  • Fix missing stack traces for NSException objects reported via NSApplication.shared.reportException(_:) on macOS. by denrase in #7284

🤖 This preview updates automatically when you update the PR.

@denrase
Copy link
Copy Markdown
Collaborator Author

denrase commented Jan 27, 2026

I have setup a project with dsym upload, here's the issue:

https://denrase.sentry.io/issues/7221278906/?project=4508007036551168&query=is%3Aunresolved&referrer=issue-stream

It does look correct to me, but please review if this is what we expect to report here.

Bildschirmfoto 2026-01-27 um 09 46 49

@denrase denrase added the ready-to-merge Use this label to trigger all PR workflows label Jan 27, 2026
@denrase denrase marked this pull request as ready for review January 27, 2026 08:49
@codecov
Copy link
Copy Markdown

codecov Bot commented Jan 27, 2026

Codecov Report

❌ Patch coverage is 70.00000% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.253%. Comparing base (7dd43c1) to head (8e1c41f).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...ecording/Monitors/SentryCrashMonitor_NSException.m 0.000% 3 Missing ⚠️
...itors/SentryCrashMonitor_NSException_StackCursor.m 82.352% 3 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@              Coverage Diff              @@
##              main     #7284       +/-   ##
=============================================
- Coverage   85.260%   85.253%   -0.008%     
=============================================
  Files          477       478        +1     
  Lines        28577     28589       +12     
  Branches     12418     12425        +7     
=============================================
+ Hits         24365     24373        +8     
- Misses        4165      4166        +1     
- Partials        47        50        +3     
Files with missing lines Coverage Δ
...ecording/Monitors/SentryCrashMonitor_NSException.m 31.250% <0.000%> (+2.948%) ⬆️
...itors/SentryCrashMonitor_NSException_StackCursor.m 82.352% <82.352%> (ø)

... and 7 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7dd43c1...8e1c41f. Read the comment docs.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jan 27, 2026

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 1218.65 ms 1251.15 ms 32.50 ms
Size 24.14 KiB 1.10 MiB 1.08 MiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
7714225 1213.24 ms 1252.28 ms 39.04 ms
1357911 1222.84 ms 1258.38 ms 35.54 ms
45eb835 1210.40 ms 1233.39 ms 22.99 ms
d540ef3 1214.37 ms 1241.06 ms 26.69 ms
b8fcca6 1228.85 ms 1259.59 ms 30.74 ms
ffe0649 1213.35 ms 1248.64 ms 35.29 ms
5ca545a 1219.06 ms 1244.59 ms 25.53 ms
015d376 1187.58 ms 1211.28 ms 23.70 ms
c519f01 1211.75 ms 1244.48 ms 32.73 ms
1357911 1224.57 ms 1261.00 ms 36.43 ms

App size

Revision Plain With Sentry Diff
7714225 24.14 KiB 1.07 MiB 1.05 MiB
1357911 24.14 KiB 1.07 MiB 1.04 MiB
45eb835 24.14 KiB 1.07 MiB 1.04 MiB
d540ef3 24.14 KiB 1.07 MiB 1.04 MiB
b8fcca6 24.14 KiB 1.08 MiB 1.06 MiB
ffe0649 24.14 KiB 1.06 MiB 1.04 MiB
5ca545a 24.14 KiB 1.06 MiB 1.04 MiB
015d376 24.14 KiB 1.09 MiB 1.07 MiB
c519f01 24.14 KiB 1.08 MiB 1.06 MiB
1357911 24.14 KiB 1.07 MiB 1.04 MiB

Previous results on branch: repro/cocoa-287-nsexception-wrong-stacktrace

Startup times

Revision Plain With Sentry Diff
1425788 1214.88 ms 1249.04 ms 34.17 ms
f1f0df6 1214.88 ms 1248.69 ms 33.82 ms
01e98f7 1215.36 ms 1251.42 ms 36.06 ms
999f921 1226.70 ms 1260.00 ms 33.30 ms

App size

Revision Plain With Sentry Diff
1425788 24.14 KiB 1.10 MiB 1.07 MiB
f1f0df6 24.14 KiB 1.08 MiB 1.06 MiB
01e98f7 24.14 KiB 1.10 MiB 1.08 MiB
999f921 24.14 KiB 1.10 MiB 1.08 MiB

Copy link
Copy Markdown
Member

@philprime philprime left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving this as it LGTM, but please consider my feedback

Comment thread Tests/SentryTests/SentryCrash/SentryCrashMonitor_NSException_StackCursor_Tests.m Outdated
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

@denrase denrase enabled auto-merge (squash) February 2, 2026 10:18
@denrase denrase merged commit c9fc5be into main Feb 3, 2026
208 of 214 checks passed
@denrase denrase deleted the repro/cocoa-287-nsexception-wrong-stacktrace branch February 3, 2026 17:37
@denrase
Copy link
Copy Markdown
Collaborator Author

denrase commented Feb 17, 2026

Reference to GH issue was missing. Closes #4472

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-to-merge Use this label to trigger all PR workflows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants