Documentation ¶
Overview ¶
Package errors is a package that implements FriendlyError. FriendlyError implements the error interface, but also has a FriendlyError() method that returns a message that is reasonable to show to end-users.
Every method that returns a FriendlyError also accepts 0 to n Fields objects may be provided and they will be combined into a single Fields, with later values overwriting newer ones.
FriendlyErrors also have With* methods that return a copy of the error with the given changes. This allows a pattern where a method defines a default FriendlyError with the friendly error message to use and then when it needs to return an error uses WithError() to add the specific error message.
Index ¶
- Constants
- func NewWrapped(err error, fields ...Fields) error
- type Fields
- type Friendly
- func (f *Friendly) Error() string
- func (f *Friendly) Fields() Fields
- func (f *Friendly) FriendlyError() string
- func (f *Friendly) SecureError() string
- func (f *Friendly) WithError(msg string, fields ...Fields) *Friendly
- func (f *Friendly) WithFriendly(friendlyMsg string, fields ...Fields) *Friendly
- func (f *Friendly) WithSecure(secureMsg string, fields ...Fields) *Friendly
Constants ¶
const DefaultFriendlyError = "An error occurred"
DefaultFriendlyError is the message that will be shown by default unless a more specific friendly value is returned.
Variables ¶
This section is empty.
Functions ¶
func NewWrapped ¶
NewWrapped takes a generic error. It returns either a new error with that message or, if nil, returns nil. Returns a generic error so if it returns nil it will no be a nil interface value to a *Friendly.
Types ¶
type Fields ¶
type Fields map[string]interface{}
Fields is the place we store extra field/value information on an error.
type Friendly ¶
type Friendly struct {
// contains filtered or unexported fields
}
Friendly is the core type of the error, representing an error that knows how to render a default string and a "friendly" string, appropriate for showing to end users.
func Extend ¶
Extend returns a new FriendlyError where the Error() message is prepended with this new message and a delimiter. If err is an *errors.Friendly then the secure message, friendly message, and fields will all be included unchanged.
func NewFriendly ¶
NewFriendly returns a new errors.Friendly with the given FriendlyError.
func (*Friendly) Error ¶
Error returns the error message, implementing the error interface. If no specific message has been provided, will fall back on FriendlyError(). The Error() value is OK to show in insecure contexts (i.e. on the client) but it just might be confusing to users.
func (*Friendly) Fields ¶
Fields returns the Fields object for this error. Fields should only be used in secure contexts (e.g. logging on a server) because they may contain private information.
func (*Friendly) FriendlyError ¶
FriendlyError is the error string that is OK to show in insecure contexts to end-users. It is generally a much simplified version of the message. If no specific FriendlyMessage has been provided, will return DefaultFriendlyError.
func (*Friendly) SecureError ¶
SecureError returns the error message that should only be shown in secure contexts, because it may include secret information. If no SecureError message has been provided, will return Error()
func (*Friendly) WithError ¶
WithError returns a copy of err where the Error() is set to msg. See a;so Extend, which prepends a new message to the front of the existing message.
func (*Friendly) WithFriendly ¶
WithFriendly returns a copy of err where the friendlyMsg is set to friendlyMsg