Skip to content

Commit 0150c0d

Browse files
committed
Document enhancedDescription better in README & function
1 parent 8755156 commit 0150c0d

File tree

2 files changed

+64
-1
lines changed

2 files changed

+64
-1
lines changed

README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,44 @@ This approach eliminates boilerplate code while keeping the error definitions co
111111
### Summary
112112

113113
> 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 _ = try Data(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.
147+
- **Clarity**: Returns clear and concise error messages, avoiding cryptic system-generated descriptions.
148+
- **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.

Sources/ErrorKit/ErrorKit.swift

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,29 @@
11
import Foundation
22

33
public enum ErrorKit {
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.
15+
///
16+
/// ## Usage Example:
17+
/// ```swift
18+
/// do {
19+
/// // Example network request
20+
/// let url = URL(string: "https://example.com")!
21+
/// let _ = try Data(contentsOf: url)
22+
/// } catch {
23+
/// print(ErrorKit.enhancedDescription(for: error))
24+
/// // Output: "You are not connected to the Internet. Please check your connection." (if applicable)
25+
/// }
26+
/// ```
527
public static func enhancedDescription(for error: Error) -> String {
628
// Any types conforming to `Throwable` are assumed to already have a good description
729
if let throwable = error as? Throwable {

0 commit comments

Comments
 (0)