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
These enhanced descriptions are community-provided and fully localized mappings of common system errors to clearer, more actionable messages.
73
+
These enhanced descriptions are community-provided and fully localized mappings of common system errors to clearer, more actionable messages. ErrorKit comes with built-in mappers for Foundation, CoreData, MapKit, and more. You can also create custom mappers for third-party libraries or your own error types.
73
74
74
75
[Read more about Enhanced Error Descriptions →](https://swiftpackageindex.com/FlineDev/ErrorKit/documentation/errorkit/enhanced-error-descriptions)
75
76
@@ -179,7 +180,7 @@ Button("Report a Problem") {
179
180
)
180
181
```
181
182
182
-
With just a simple SwiftUI modifier, you can automatically include all log messages from Apple's unified logging system.
183
+
With just a simple built-in SwiftUI modifier and the `logAttachment` helper function, you can easily include all log messages from Apple's unified logging system and let your users send them to you via email. Other integrations are also supported.
183
184
184
185
[Read more about User Feedback and Logging →](https://swiftpackageindex.com/FlineDev/ErrorKit/documentation/errorkit/user-feedback-with-logs)
185
186
@@ -193,6 +194,8 @@ ErrorKit's features are designed to complement each other while remaining indepe
193
194
194
195
3.**Save time with ready-made tools**: built-in error types for common scenarios and simple log collection for user feedback.
195
196
197
+
4.**Extend with custom mappers**: Create error mappers for any library to improve error messages across your entire application.
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:
/// This function analyzes the given `Error` and returns a clearer, more helpful message than the default system-provided description.
12
12
/// All descriptions are localized, ensuring that users receive messages in their preferred language where available.
13
13
///
14
-
/// The list of user-friendly messages is maintained and regularly improved by the developer community. Contributions are welcome—if you find bugs or encounter new errors, feel free to submit a pull request (PR) for review.
14
+
/// The function uses registered error mappers to generate contextual messages for errors from different frameworks and libraries.
15
+
/// ErrorKit includes built-in mappers for `Foundation`, `CoreData`, `MapKit`, and more.
16
+
/// You can extend ErrorKit's capabilities by registering custom mappers using ``registerMapper(_:)``.
17
+
/// Custom mappers are queried in reverse order, meaning user-provided mappers take precedence over built-in ones.
15
18
///
16
-
/// Errors from various domains, such as `Foundation`, `CoreData`, `MapKit`, and more, are supported. As the project evolves, additional domains may be included to ensure comprehensive coverage.
19
+
/// The list of user-friendly messages is maintained and regularly improved by the developer community.
20
+
/// Contributions are welcome—if you find bugs or encounter new errors, feel free to submit a pull request (PR) for review.
17
21
///
18
22
/// - Parameter error: The `Error` instance for which a user-friendly message is needed.
19
23
/// - Returns: A `String` containing an enhanced, localized, user-readable error message.
0 commit comments