github.com/iamrgon/errdecode (go): Package errdecode provides a way to represent rules for classifying error values returned by your application.  Typically, errors in the application domain are either:  a. returned as-is  b. annotated, e.g., using the %w verb (go 1.13) or similar means  It is preferable to follow approach (b) near the top of the call stack, so errors can be explained to an end user.  These error classification rules can be composed as such:  Once classified, New returns a decoder that can be used to classify and decode encountered error values into pre-defined messages.  The end user sees the message for the classifed error. In this case, "The provided token is not valid." rather than the terse, "invalid token".  In the case that an error type needs to be matched, a MatcherFunc can be provided when declaring the rule. This is most relevant when creating rules to match custom types, e.g., if following approach (a) without any top-of-the-call stack handling.  This approach can be further extended by defining an optional encoder that can classify all encountered errors.  When there are scenarios where a classified error will need to undergo further transformations, as is the case when integrating localized text lookups, an optional message translator can integrate the key-based lookup.
Keywords: errors|golang