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
/// 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.
/// A protocol for mapping domain-specific errors to user-friendly messages.
2
+
///
3
+
/// `ErrorMapper` allows users to extend ErrorKit's error mapping capabilities by providing custom mappings for errors from specific frameworks, libraries, or domains.
4
+
///
5
+
/// # Overview
6
+
/// ErrorKit comes with built-in mappers for Foundation, CoreData, and MapKit errors.
7
+
/// You can add your own mappers for other frameworks or custom error types using the ``ErrorKit/registerMapper(_:)`` function.
8
+
/// ErrorKit will query all registered mappers in reverse order until one returns a non-nil result. This means, the last added mapper takes precedence.
/// Your mapper will be called automatically when using ``ErrorKit/userFriendlyMessage(for:)``:
56
+
/// ```swift
57
+
/// do {
58
+
/// let user = try await Auth.auth().signIn(withEmail: email, password: password)
59
+
/// } catch {
60
+
/// let message = ErrorKit.userFriendlyMessage(for: error)
61
+
/// // Message will be generated from FirebaseErrorMapper for Auth/Firestore/Storage errors
62
+
/// }
63
+
/// ```
64
+
publicprotocolErrorMapper{
65
+
/// Maps a given error to a user-friendly message if possible.
66
+
///
67
+
/// This function is called by ErrorKit when attempting to generate a user-friendly error message.
68
+
/// It should check if the error is of a type it can handle and return an appropriate message, or return nil to allow other mappers to process the error.
69
+
///
70
+
/// # Implementation Guidelines
71
+
/// - Return nil for errors your mapper doesn't handle
72
+
/// - Always use String(localized:) for message localization
73
+
/// - Keep messages clear, actionable, and non-technical
74
+
/// - Avoid revealing sensitive information
75
+
/// - Consider the user experience when crafting messages
/// - Note: Any error cases you don't provide a return value for will simply keep their original message. So only override the unclear ones or those that are not localized or you want other kinds of improvements for. No need to handle all possible cases just for the sake of it.
97
+
///
98
+
/// - Parameter error: The error to potentially map to a user-friendly message
99
+
/// - Returns: A user-friendly message if this mapper can handle the error, or nil otherwise
0 commit comments