getsentry / sentry-cocoa

The official Sentry SDK for iOS, tvOS, macOS, watchOS.
https://sentry.io/for/cocoa/
MIT License
803 stars 317 forks source link

NSDebugDescriptionErrorKey does not change the error description on the Issues page #2223

Closed iamjamesim closed 2 years ago

iamjamesim commented 2 years ago

Core or SDK?

Platform/SDK

Which part? Which one?

ios/usage/#customizing-error-descriptions

Description

Excerpt from Customizing Error Descriptions section on the Usage for iOS page:

By default, Sentry will display the error code as the error description. For custom error types, you may want to provide a custom description that makes it easier to identify the error in the Issues page. You can provide a custom description for NSError values by adding a description to the userInfo dictionary with the key NSDebugDescriptionErrorKey.

Although I've added a description to the userInfo dictionary with NSDebugDescriptionErrorKey, I'm not seeing the description anywhere on the Issues page. I do, however, see the description under the User Info section once I click into the specific issue's details page.

Suggested Solution

Show the custom descriptions on the Issues page.

imatwawana commented 2 years ago

@getsentry/team-mobile - should the text here be changed to say the Issue Details page?

iamjamesim commented 2 years ago

If at all possible, I would like to request Sentry to show the custom description instead of the error code on the Issues page. Sadly, the error code can sometimes be completely meaningless, in which case it becomes very difficult to distinguish issues from one another.

Screen Shot 2022-09-23 at 8 41 22 PM
brustolin commented 2 years ago

@imatwawana I dont think this is a documentation problem but an implementation one. I'll transfer this to coca repo.

brustolin commented 2 years ago

@imjamesim Thanks for pointing this out. We going to investigate.

philipphofmann commented 2 years ago

@imjamesim, can you please share a code snippet for us to reproduce your issue?

iamjamesim commented 2 years ago

@philipphofmann here's a snippet that shows how we're using NSDebugDescriptionErrorKey to provide a custom debug description for Apollo's GraphQLError:

extension GraphQLError: CustomNSError {

    ...

    public var errorUserInfo: [String: Any] {
        var userInfo = [String: Any]()
        if let message = message {
            userInfo[NSDebugDescriptionErrorKey] = message
        }
        return userInfo
    }
}
philipphofmann commented 2 years ago

I just tried

class MyError: CustomNSError {
    public var errorUserInfo: [String: Any] {
        var userInfo = [String: Any]()
        userInfo[NSDebugDescriptionErrorKey] = "My Philipp Custom message"
        return userInfo
    }
}

// ...

let error = MyError()
SentrySDK.capture(error: error)

And it results in

Screen Shot 2022-09-29 at 15 09 55

Which SDK version are you using, @imjamesim? This feature is only available since 7.25.0. I think we have to point this out in the docs.

philipphofmann commented 2 years ago

Docs PR https://github.com/getsentry/sentry-docs/pull/5583.

iamjamesim commented 2 years ago

@philipphofmann ah we were on 7.23.0. I just confirmed this works as expected on 7.27.0. Thanks for the clarification!