You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Sources/ErrorKit/ErrorKit.docc/Guides/Enhanced-Error-Descriptions.md
+38-13Lines changed: 38 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -75,18 +75,18 @@ do {
75
75
}
76
76
```
77
77
78
-
If the error already conforms to `Throwable`, its `userFriendlyMessage` is used. For system errors, ErrorKit provides an enhanced description from its built-in mappings.
78
+
If the error already conforms to `Throwable`, its `userFriendlyMessage` is used. For system errors, ErrorKit provides an enhanced description from its built-in mappers.
79
79
80
80
### Localization Support
81
81
82
-
All enhanced error messages are fully localized using the `String.localized(key:defaultValue:)` pattern, ensuring users receive messages in their preferred language where available.
82
+
All enhanced error messages are fully localized using the `String(localized:)` pattern, ensuring users receive messages in their preferred language where available.
83
83
84
84
### How It Works
85
85
86
86
The `userFriendlyMessage(for:)` function follows this process to determine the best error message:
87
87
88
88
1. If the error conforms to `Throwable`, it uses the error's own `userFriendlyMessage`
89
-
2. It tries domain-specific handlers to find available enhanced versions
89
+
2. It queries registered error mappers to find enhanced descriptions
90
90
3. If the error conforms to `LocalizedError`, it combines its localized properties
91
91
4. As a fallback, it formats the NSError domain and code along with the standard `localizedDescription`
92
92
@@ -95,32 +95,57 @@ The `userFriendlyMessage(for:)` function follows this process to determine the b
95
95
You can help improve ErrorKit by contributing better error descriptions for common error types:
96
96
97
97
1. Identify cryptic error messages from system frameworks
98
-
2. Implement domain-specific handlers or extend existing ones (see folder `EnhancedDescriptions`)
98
+
2. Implement domain-specific handlers or extend existing ones (see folder `ErrorMappers`)
99
99
3. Use clear, actionable language that helps users understand what went wrong
100
100
4. Include localization support for all messages (no need to actually localize, we'll take care)
101
101
102
102
Example contribution to handle a new error type:
103
103
104
104
```swift
105
-
// In ErrorKit+Foundation.swift
105
+
// In FoundationErrorMapper.swift
106
106
caselet jsonError as NSError where jsonError.domain== NSCocoaErrorDomain && jsonError.code==3840:
0 commit comments