sentry-cocoa: Error message is not included for Swift errors
Environment
How do you use Sentry?
SaaS
Which SDK and version?
Sentry Cocoa 7.5.0
Steps to Reproduce
For example, I have this error:
struct UnexpectedNilError: LocalizedError {
let message: String?
let file: String
let line: Int
init(
_ message: String?,
file: String = #fileID,
line: Int = #line
) {
self.message = message
self.file = file
self.line = line
#if canImport(Sentry)
SentrySDK.capture(error: self)
#endif
}
var errorDescription: String { message }
var failureReason: String {
"Unexpected nil encountered at \(file):\(line)"
}
}
If I throw it, it ends up in Sentry as:
Notice how the subtitle is just Code: 1 and the error message and failure reason are nowhere to be seen in the report details.
Example event: https://sentry.io/organizations/sindresorhus/issues/2765092409/events/aacc22d1335443f18d7453315c076f7a/ (Not sure if you can access it?)
However, if I send an NSError, I get the correct details, where I can see a NSLocalizedDescription key in the report details.
Expected Result
I expected to see the error message and failure reason in the report.
Actual Result
The report is missing key details.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 4
- Comments: 17 (12 by maintainers)
Came across this đź§µ after trying to find a way to customize our error reports on Sentry.
This is true and it’s really difficult to just look at Sentry dashboard and figure out which is which. For instance:
Ups sorry, my mistake. Your PR #1496 doesn’t have an impact on grouping because we group by domain and error code https://github.com/getsentry/sentry-cocoa/blob/a06565c2a78dcda8b12c677761ca83cceb136067/Sources/Sentry/SentryClient.m#L228-L232.
I’m going to reopen #1496
So an
Error’s description is missing from the Sentry UI. Both localized and debug descriptions are ignored. And still, no plans and no documentation explaining how Sentry expects errors to be reported in a way that provides meaningful information. #1496 fixes the issue, and it implemented the suggestions in this thread, but it was ignored and autoclosed. How does Sentry expect us to interpret this?@philipphofmann is there any plans to revisit this, or my PR? To this day we are having to run a fork of the SDK with my changes because if this issue which is a maintenance headache I’d rather not have.
Is there any plans to make it possible to customise this? Only being able to see “Code: X” makes it very difficult to scan through a long list of errors, I’d much rather it showed the error description if one is available, or both, e.g. “Some important error (code: 1)”.
A simple change would be to always use
localizedDescription- this defaults to a message based on the domain or code but can be overridden by setting the appropriate key on the userInfo dictionary or conforming to theLocalizedErrorprotocol and implementing theerrorDescriptionproperty:https://github.com/Shimmur/sentry-cocoa/commit/149b8f45f5283b5cae26ba1c97db369722abae11
Please keep open.