NSException does not include reason
Platform
macOS
Installed
Swift Package Manager
Version
8.9.4
Steps to Reproduce
Call some Apple API which throws an NSException.
Expected Result
I expected the crash report to help me solve the crash, but without a .reason description, it's hard to pin-point the issue.
Actual Result
The report only includes a stack trace, but without the exception reason, it's hard to fix the issue.
All it says is:
NSException > terminating due to uncaught exception of type NSException
Example report: https://sindresorhus.sentry.io/issues/4439865559/events/ec44fb881aa542548650394ce017d6c6/
The stack trace in the above report points to this line: https://github.com/sindresorhus/Actions/blob/e2d1b2ffecb185df81311609d7b0f4cd29f57cf5/Shared/Actions/ParseCSV.swift#L102-L105
This is a big problem, because pretty much all crashes I get are NSException from Apple's frameworks. All my apps are using safe Swift, so they don't generally crash in the app code.
Are you willing to submit a PR?
No
Hello @sindresorhus, thanks for suggestion, we will look into it.
Hello @sindresorhus. Could you help us reproduce this?
I tried this code
func convertObject() throws {
let result = try JSONSerialization.data(withJSONObject: [self])
print(result)
}
But this is the report I get at Sentry
This issue has gone three weeks without activity. In another week, I will close it.
But! If you comment or otherwise update it, I will reset the clock, and if you remove the label Waiting for: Community, I will leave it alone ... forever!
"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀
I cannot reproduce either, so I guess it was fixed in Sentry Cocoa since v8.9.4 (the version of the exmaple report in the issue).
Ok, I'm still seeing this in production (with Sentry Cocoa 8.13): https://sindresorhus.sentry.io/issues/4529970622/events/6d9872f2dd7e426fa54a2c6aee456d0c/
Some things I noticed about it: It crashes inside AppKit, not in the app, and it also failed to symbolicate. I'm not sure if that would affect getting the exception reason.
Thanks for reporting this, @sindresorhus. We have to investigate this and get back to you.
@philipphofmann I think this was accidentally closed.
Another one:
EXC_BREAKPOINT 0x000000018fd550e0 start + 2360
https://sindresorhus.sentry.io/issues/4525409382/events/eeadeaca905e4e17abaa6e1718f3c855/
@sindresorhus would you be able to provide a minimal reproducible example? I tried to reproduce this as closely as possible using our macOS sample app, but was unable to.
I'm not able to reproduce it myself. The report is from my users. But I keep seeing this problem in many crash reports from various apps, so it's pretty wide spread and makes most crash reports useless.
Still happening: https://sindresorhus.sentry.io/issues/4525304601/events/d11ffdd9fbef4ae9a80e744d6046cf73/
EXC_BREAKPOINT 0x000000018232d0e0 start + 2360
Some more:
- https://sindresorhus.sentry.io/issues/4525409382/events/7ed0fd3ee3b94593893da298b687b56b/?project=6276511&referrer=next-event
EXC_BREAKPOINT 0x00000001804b90e0 start + 2360
- https://sindresorhus.sentry.io/issues/4525409382/events/860338d12e5b481f847b73cbcaf3ce2e/?project=6276511&referrer=previous-event
EXC_BREAKPOINT 0x0000000182fd10e0 start + 2360 > XTUM
- https://sindresorhus.sentry.io/issues/4525409382/events/2a1e0afd32de47d79b68b1b8f2714437/?project=6276511&referrer=previous-event
EXC_BREAKPOINT d 0x000000018d12d0e0 start + 2360
@sindresorhus, do you use the SentryCrashExceptionApplication as pointed out in our docs? If not, can you try and see if you get the .reason when using this approach?
@philipphofmann The app is a SwiftUI lifecycle app (which most apps are these days), so that is not possible. However, I do set UserDefaults.standard.register(defaults: ["NSApplicationCrashOnExceptions": true]).
I also have .enableSwizzling = false in the Sentry config because it caused too many crashes.
I just tried to reproduce your issue with calling UserDefaults.standard.register(defaults: ["NSApplicationCrashOnExceptions": true]) in the AppDelegate and then calling
let exception = NSException(name: NSExceptionName("My Custom exception"), reason: "User clicked the button", userInfo: userInfo)
NSApplication.shared.reportException(exception)
The reported NSException in Sentry shows the reason. As the NSException.reason property is optional, see docs, could it be that your reported NSExceptions don't have a reason?
Personal note: I think we should document the UserDefaults.standard.register(defaults: ["NSApplicationCrashOnExceptions": true]).
The reported NSException in Sentry shows the reason. As the NSException.reason property is optional, see docs, could it be that your reported NSExceptions don't have a reason?
That is possible, but it's a bit suspicious that pretty much all exceptions are missing a .reason. If this is really the case, I think Sentry should indicate so. Maybe with a reason as <Missing Reason> or something.
It also looks like the exception parsing is a bit off as some exceptions are reported as:
EXC_BREAKPOINT
d 0x000000018d12d0e0 start + 2360
Notice the d.
https://sindresorhus.sentry.io/issues/4525409382/events/2a1e0afd32de47d79b68b1b8f2714437/?project=6276511&referrer=previous-event
Personal note: I think we should document the UserDefaults.standard.register(defaults: ["NSApplicationCrashOnExceptions": true]).
Definitely. I think all other crash reporting solutions recommend this. I remember starting to add it to my apps many years ago when I was using Crashlytics (before Google bought them).
@sindresorhus, it turns out we wrote the reason into the wrong field when writing the crash report, so https://github.com/getsentry/sentry-cocoa/pull/3705 could surface your missing reasons. If it doesn't, please reopen this issue.
I opened another issue for adding a missing reason (https://github.com/getsentry/sentry-cocoa/issues/3265#issuecomment-1973276793) see: https://github.com/getsentry/sentry-cocoa/issues/3706
I created an extra issue for the exception parsing seeming a bit off https://github.com/getsentry/sentry-cocoa/issues/3265#issuecomment-1973278211; see https://github.com/getsentry/sentry-cocoa/issues/3707
And, I opened an issue for the docs https://github.com/getsentry/sentry-docs/issues/9313 to document UserDefaults.standard.register(defaults: ["NSApplicationCrashOnExceptions": true]).