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: README.md
+41Lines changed: 41 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -111,3 +111,44 @@ This approach eliminates boilerplate code while keeping the error definitions co
111
111
### Summary
112
112
113
113
> Conform your custom error types to `Throwable` instead of `Error` or `LocalizedError`. The `Throwable` protocol requires only `localizedDescription: String`, ensuring your error messages are exactly what you expect – no surprises.
114
+
115
+
116
+
## Enhanced Error Descriptions with `enhancedDescription(for:)`
117
+
118
+
ErrorKit goes beyond simplifying error handling — it enhances the clarity of error messages by providing improved, localized descriptions. With the `ErrorKit.enhancedDescription(for:)` function, developers can deliver clear, user-friendly error messages tailored to their audience.
119
+
120
+
### How It Works
121
+
122
+
The `enhancedDescription(for:)` function analyzes the provided `Error` and returns an enhanced, localized message. It draws on a community-maintained collection of descriptions to ensure the messages are accurate, helpful, and continuously evolving.
123
+
124
+
### Supported Error Domains
125
+
126
+
ErrorKit supports errors from various domains such as `Foundation`, `CoreData`, `MapKit`, and more. These domains are continuously updated, providing coverage for the most common error types in Swift development.
127
+
128
+
### Usage Example
129
+
130
+
Here’s how to use `enhancedDescription(for:)` to handle errors gracefully:
131
+
132
+
```swift
133
+
do {
134
+
// Attempt a network request
135
+
let url =URL(string: "https://example.com")!
136
+
let_=tryData(contentsOf: url)
137
+
} catch {
138
+
// Print or show the enhanced error message to a user
139
+
print(ErrorKit.enhancedDescription(for: error))
140
+
// Example output: "You are not connected to the Internet. Please check your connection."
141
+
}
142
+
```
143
+
144
+
### Why Use `enhancedDescription(for:)`?
145
+
146
+
-**Localization**: Error messages are localized to ~40 languages to provide a better user experience.
-**Community Contributions**: The descriptions are regularly improved by the developer community. If you encounter a new or unexpected error, feel free to contribute by submitting a pull request.
149
+
150
+
### Contribution Welcome!
151
+
152
+
Found a bug or missing description? We welcome your contributions! Submit a pull request (PR), and we’ll gladly review and merge it to enhance the library further.
153
+
154
+
> **Note:** The enhanced error descriptions are constantly evolving, and we’re committed to making them as accurate and helpful as possible.
Copy file name to clipboardExpand all lines: Sources/ErrorKit/ErrorKit.swift
+23-1Lines changed: 23 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,29 @@
1
1
import Foundation
2
2
3
3
publicenumErrorKit{
4
-
/// Provides improved and more helpful error messages for a community-maintained list of common system errors.
4
+
/// Provides enhanced, user-friendly, localized error descriptions for a wide range of system errors.
5
+
///
6
+
/// This function analyzes the given `Error` and returns a clearer, more helpful message than the default system-provided description.
7
+
/// All descriptions are localized, ensuring that users receive messages in their preferred language where available.
8
+
///
9
+
/// The list of enhanced descriptions 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.
10
+
///
11
+
/// 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.
12
+
///
13
+
/// - Parameter error: The `Error` instance for which an enhanced description is needed.
14
+
/// - Returns: A `String` containing an enhanced, localized, user-readable error message.
0 commit comments