Skip to content

Commit d11e9d4

Browse files
fix(apple): Clarify custom error description (#6495)
Improve code sample for customizing error descriptions.
1 parent bb1d4de commit d11e9d4

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/platform-includes/capture-error/apple.mdx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,23 @@ By default, Sentry will display the error code as the error description. For cus
3636
This can be particularly useful for Swift enum error types that conform to `Error`, where the error code can be hard to match with an enum case. To customize the description for Swift `Error` types, you should conform to the `CustomNSError` protocol and return a user info dictionary:
3737
3838
```swift {tabTitle:Swift}
39+
enum MyCustomError: Error {
40+
case indexOutOfBounds
41+
case enumeratingWhileMutating
42+
}
43+
3944
extension MyCustomError: CustomNSError {
4045
var errorUserInfo: [String : Any] {
41-
[NSDebugDescriptionErrorKey: "Custom error description"]
46+
func getDebugDescription() -> String {
47+
switch self {
48+
case .indexOutOfBounds:
49+
return "indexOutOfBounds"
50+
case .enumeratingWhileMutating:
51+
return "enumeratingWhileMutating"
52+
}
53+
}
54+
55+
return [NSDebugDescriptionErrorKey: getDebugDescription()]
4256
}
4357
}
4458
```

0 commit comments

Comments
 (0)