Documentation
¶
Overview ¶
Package failure implements an opaque error pattern based several of the most common types of errors that occur when developing microservices.
Index ¶
- Constants
- func BadRequest(format string, a ...interface{}) error
- func Config(format string, a ...interface{}) error
- func Defer(format string, a ...interface{}) error
- func Flatten(err error) error
- func Forbidden(format string, a ...interface{}) error
- func Ignore(format string, a ...interface{}) error
- func InvalidParam(format string, a ...interface{}) error
- func IsAnyAuthFailure(e error) bool
- func IsBadRequest(e error) bool
- func IsConfig(e error) bool
- func IsDefer(e error) bool
- func IsForbidden(e error) bool
- func IsIgnore(e error) bool
- func IsInvalidParam(e error) bool
- func IsMultiple(e error) bool
- func IsNotAuthenticated(e error) bool
- func IsNotAuthorized(e error) bool
- func IsNotFound(e error) bool
- func IsServer(err error) bool
- func IsShutdown(e error) bool
- func IsStartup(e error) bool
- func IsSystem(err error) bool
- func IsTimeout(e error) bool
- func IsValidation(e error) bool
- func ListFormatFn(es []error) string
- func MultiResult(e error) ([]error, bool)
- func NotAuthenticated(format string, a ...interface{}) error
- func NotAuthorized(format string, a ...interface{}) error
- func NotFound(format string, a ...interface{}) error
- func Server(format string, a ...interface{}) error
- func Shutdown(format string, a ...interface{}) error
- func Startup(format string, a ...interface{}) error
- func System(format string, a ...interface{}) error
- func Timeout(format string, a ...interface{}) error
- func ToBadRequest(e error, format string, a ...interface{}) error
- func ToConfig(e error, format string, a ...interface{}) error
- func ToDefer(e error, format string, a ...interface{}) error
- func ToForbidden(e error, format string, a ...interface{}) error
- func ToIgnore(e error, format string, a ...interface{}) error
- func ToInvalidParam(e error, format string, a ...interface{}) error
- func ToNotAuthenticated(e error, format string, a ...interface{}) error
- func ToNotAuthorized(e error, format string, a ...interface{}) error
- func ToNotFound(e error, format string, a ...interface{}) error
- func ToServer(e error, format string, a ...interface{}) error
- func ToShutdown(e error, format string, a ...interface{}) error
- func ToStartup(e error, format string, a ...interface{}) error
- func ToSystem(e error, format string, a ...interface{}) error
- func ToTimeout(e error, format string, a ...interface{}) error
- func ToValidation(e error, format string, a ...interface{}) error
- func Validation(format string, a ...interface{}) error
- func Wrap(err error, msg string, a ...interface{}) error
- type Group
- type Multi
- type MultiFormatFn
Constants ¶
const ( SystemMsg = "system failure" ServerMsg = "server failure" NotFoundMsg = "not found failure" NotAuthorizedMsg = "not authorized failure" NotAuthenticatedMsg = "not authenticated failure" ForbiddenMsg = "access is forbidden" ValidationMsg = "validation failure" DeferMsg = "failure occurred inside defer" IgnoreMsg = "ignore failure" ConfigMsg = "config failure" InvalidParamMsg = "invalid param failure" ShutdownMsg = "system shutdown failure" BadRequestMsg = "bad request" TimeoutMsg = "timeout failure" StartupMsg = "failure occurred during startup" )
Variables ¶
This section is empty.
Functions ¶
func BadRequest ¶ added in v0.6.0
BadRequest is used to signal that the app should shut down.
func Config ¶ added in v0.3.0
Config is used to signify that error occurred when processing the application configuration
func Flatten ¶ added in v0.9.0
Flatten flattens the given error, merging any *Errors together into a single *Error.
func Forbidden ¶ added in v0.7.0
Forbidden is used to signify either not authenticated or not authorized
func Ignore ¶
Ignore is used to signify that error should not be acted on, it's up to the handler to decide to log these errors or not.
func InvalidParam ¶ added in v0.4.0
InvalidParam is to indicate that the param of a function or any parameter in general is invalid
func IsAnyAuthFailure ¶ added in v0.7.0
IsAnyAuthFailure can be used to determine if any of the following we used: NotAuthenticated, NotAuthorized, Forbidden
func IsBadRequest ¶ added in v0.6.0
func IsForbidden ¶ added in v0.7.0
func IsInvalidParam ¶ added in v0.4.0
func IsMultiple ¶ added in v0.9.0
func IsNotAuthenticated ¶ added in v0.7.0
func IsNotAuthorized ¶ added in v0.7.0
func IsNotFound ¶
func IsShutdown ¶ added in v0.5.0
func IsValidation ¶
func ListFormatFn ¶ added in v0.9.0
ListFormatFn is a basic formatter that outputs the number of errors that occurred along with a bullet point list of the errors.
func MultiResult ¶ added in v0.9.0
func NotAuthenticated ¶ added in v0.7.0
NotAuthenticated is used to signify that a resource's identity verification failed. They are not who they claim to be
func NotAuthorized ¶ added in v0.7.0
NotAuthorized is used to signify that a resource does not have sufficient access to perform a given task
func NotFound ¶
NotFound is used to signify that whatever resource you were looking for does not exist and that fact it does not exist is an error.
func Server ¶
Server has the same meaning as Platform or System, it can be used instead if you don't like how Platform or System reads in your code.
func Startup ¶ added in v0.9.0
Startup is used to signify a failure preventing the system from starting up
func System ¶
System is has the same meaning as Platform or Server, it can be used instead if you don't like how Platform reads in your code
func Timeout ¶ added in v0.8.0
Timeout is used to signify that error because something was taking too long
func ToBadRequest ¶ added in v0.6.0
func ToForbidden ¶ added in v0.7.0
func ToIgnore ¶
ToIgnore converts `e` into the root cause of ignoreErr, it informs the system to ignore error. Used typically to log results and do not act on the error itself.
func ToInvalidParam ¶ added in v0.4.0
func ToNotAuthenticated ¶ added in v0.7.0
func ToNotAuthorized ¶ added in v0.7.0
func ToNotFound ¶
func ToShutdown ¶ added in v0.5.0
func ToValidation ¶
func Validation ¶
Validation is used to signify that a validation rule as been violated
Types ¶
type Group ¶ added in v0.9.0
type Group struct {
// contains filtered or unexported fields
}
Group is a collection of goroutines which return errors that need to be coalesced.
type Multi ¶ added in v0.9.0
type Multi struct {
Failures []error
Formatter MultiFormatFn
}
func Multiple ¶ added in v0.9.0
func Multiple(errs []error, opt ...MultiFormatFn) *Multi
func (*Multi) ErrorOrNil ¶ added in v0.9.0
ErrorOrNil returns an error interface if this Error represents a list of errors, or returns nil if the list of errors is empty. This function is useful at the end of accumulation to make sure that the value returned represents the existence of errors.
func (*Multi) Unwrap ¶ added in v0.9.0
Unwrap returns an error from Multi (or nil if there are no errors). This error returned will further support Unwrap to get the next error, etc. The order will match the order of Errors in the failure.Multi at the time of calling.
The resulting error supports errors.As/Is/Unwrap, so you can continue to use the stdlib errors package to introspect further.
This will perform a shallow copy of the errors slice. Any errors appended to this error after calling Unwrap will not be available until a new Unwrap is called on the failure.Multi.
func (*Multi) WrappedErrors ¶ added in v0.9.0
WrappedErrors returns the list of errors that this Error is wrapping. It is an implementation of the errwrap.Wrapper interface so that failure.Multi can be used with that library.
This method is not safe to be called concurrently. Unlike accessing the Failures field directly, this function also checks if the Multi is nil to prevent a null-pointer panic. It satisfies the errwrap.Wrapper interface.