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 AlreadyExists(format string, a ...interface{}) error
- func BadRequest(msg 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 GetInvalidFields(e error) (map[string]string, bool)
- func Ignore(format string, a ...interface{}) error
- func InvalidFields(f map[string]string, msg string, a ...interface{}) error
- func InvalidParam(format string, a ...interface{}) error
- func InvalidState(format string, a ...interface{}) error
- func IsAlreadyExists(e error) bool
- 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 IsInvalidFields(e error) bool
- func IsInvalidParam(e error) bool
- func IsInvalidState(e error) bool
- func IsMissingFromContext(e error) bool
- func IsMultiple(e error) bool
- func IsNoChange(e error) bool
- func IsNotAuthenticated(e error) bool
- func IsNotAuthorized(e error) bool
- func IsNotFound(e error) bool
- func IsOutOfRange(e error) bool
- func IsPanic(e error) bool
- func IsRestAPI(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 IsWarn(e error) bool
- func ListFormatFn(es []error) string
- func MissingFromContext(format string, a ...interface{}) error
- func MultiResult(e error) ([]error, bool)
- func NoChange(format string, a ...interface{}) error
- func NotAuthenticated(format string, a ...interface{}) error
- func NotAuthorized(format string, a ...interface{}) error
- func NotFound(format string, a ...interface{}) error
- func OutOfRange(format string, a ...interface{}) error
- func Panic(format string, a ...interface{}) error
- func RestError(e error) (error, bool)
- func RestMessage(e error) (string, bool)
- func RestStatusCode(e error) (int, bool)
- 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 ToAlreadyExists(e error, format string, a ...interface{}) error
- func ToBadRequest(e error, msg 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 ToInvalidState(e error, format string, a ...interface{}) error
- func ToMissingFromContext(e error, format string, a ...interface{}) error
- func ToNoChange(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 ToOutOfRange(e error, format string, a ...interface{}) error
- func ToPanic(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 ToWarn(e error, format string, a ...interface{}) error
- func Validation(format string, a ...interface{}) error
- func Warn(format string, a ...interface{}) error
- func Wrap(err error, msg string, a ...interface{}) error
- type Group
- type Multi
- type MultiFormatFn
- type RestAPI
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" TimeoutMsg = "timeout failure" StartupMsg = "failure occurred during startup" PanicMsg = "panic" BadRequestMsg = "bad request" InvalidAPIFieldsMsg = "http input fields are not valid" MissingFromContextMsg = "resource not in context" AlreadyExistsMsg = "duplicate resource already exists" OutOfRangeMsg = "out of range failure" WarnMsg = "warning" NoChangeMsg = "no change has occurred" InvalidStateMsg = "invalid state" )
Variables ¶
This section is empty.
Functions ¶
func AlreadyExists ¶ added in v0.11.0
AlreadyExists is used to indicate that the given resource already exists
func BadRequest ¶ added in v0.6.0
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 InvalidFields ¶ added in v0.10.0
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 InvalidState ¶ added in v0.14.0
InvalidState is used to signal that the resource is not in a valid state
func IsAlreadyExists ¶ added in v0.11.0
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 IsInvalidFields ¶ added in v0.10.0
func IsInvalidParam ¶ added in v0.4.0
func IsInvalidState ¶ added in v0.14.0
func IsMissingFromContext ¶ added in v0.11.0
func IsMultiple ¶ added in v0.9.0
func IsNoChange ¶ added in v0.13.0
func IsNotAuthenticated ¶ added in v0.7.0
func IsNotAuthorized ¶ added in v0.7.0
func IsNotFound ¶
func IsOutOfRange ¶ added in v0.12.0
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 MissingFromContext ¶ added in v0.11.0
MissingFromContext is used to indicate a resource was supposed to be in the context but is missing
func MultiResult ¶ added in v0.9.0
func NoChange ¶ added in v0.13.0
NoChange is used to signal that if you expected something to change, it has not.
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 OutOfRange ¶ added in v0.12.0
OutOfRange is used to signal that the offset of a map is invalid or some index for a list is incorrect
func Panic ¶ added in v0.10.0
Panic is used in panic recovery blocks or to indicate that you should panic if you receive this error
func RestMessage ¶ added in v0.10.0
func RestStatusCode ¶ added in v0.10.0
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 ToAlreadyExists ¶ added in v0.11.0
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 ToInvalidState ¶ added in v0.14.0
func ToMissingFromContext ¶ added in v0.11.0
func ToNoChange ¶ added in v0.13.0
func ToNotAuthenticated ¶ added in v0.7.0
func ToNotAuthorized ¶ added in v0.7.0
func ToNotFound ¶
func ToOutOfRange ¶ added in v0.12.0
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.