{"modulePath":"github.com/xgodev/boost","version":"v1.11.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package errors\n\nPackage errors provides an easy way to annotate errors without losing the original error context.\n\n## Functions\n\n```go\nfunc AlreadyExistsf(format string, args ...interface{}) error\n```\nAlreadyExistsf returns an error which satisfies IsAlreadyExists(). Its message is the formatted text followed by \" already exists\", so the format names the thing: AlreadyExistsf(\"sku %s\", sku) says \"sku cap already exists\".\n\n```go\nfunc Annotate(other error, message string) error\n```\nAnnotate is used to add extra context to an existing error. The location of the Annotate call is recorded with the annotations. The file, line and function are also recorded.\n\nFor example:\n\n\tif err := SomeFunc(); err != nil {\n\t    return errors.Annotate(err, \"failed to frombulate\")\n\t}\n\n```go\nfunc Annotatef(other error, format string, args ...interface{}) error\n```\nAnnotatef is used to add extra context to an existing error. The location of the Annotate call is recorded with the annotations. The file, line and function are also recorded.\n\nFor example:\n\n\tif err := SomeFunc(); err != nil {\n\t    return errors.Annotatef(err, \"failed to frombulate the %s\", arg)\n\t}\n\n```go\nfunc BadRequestf(format string, args ...interface{}) error\n```\nBadRequestf returns an error which satisfies IsBadRequest().\n\n```go\nfunc Cause(err error) error\n```\nCause returns the cause of the given error.  This will be either the original error, or the result of a Wrap or Mask call.\n\nCause is the usual way to diagnose errors that may have been wrapped by the other errors functions.\n\n```go\nfunc Conflictf(format string, args ...interface{}) error\n```\nConflictf returns an error which satisfies IsConflict().\n\n```go\nfunc DeferredAnnotatef(err *error, format string, args ...interface{})\n```\nDeferredAnnotatef annotates the given error (when it is not nil) with the given format string and arguments (like fmt.Sprintf). If \\*err is nil, DeferredAnnotatef does nothing. This method is used in a defer statement in order to annotate any resulting error with the same message.\n\nFor example:\n\n\tdefer DeferredAnnotatef(\u0026err, \"failed to frombulate the %s\", arg)\n\n```go\nfunc Details(err error) string\n```\nDetails returns information about the stack of errors wrapped by err, in the format:\n\n\t[{filename:99: error one} {otherfile:55: cause of error one}]\n\nThis is a terse alternative to ErrorStack as it returns a single line.\n\n```go\nfunc ErrorStack(err error) string\n```\nErrorStack returns a string representation of the annotated error. If the error passed as the parameter is not an annotated error, the result is simply the result of the Error() method on that error.\n\nIf the error is an annotated error, a multi-line string is returned where each line represents one entry in the annotation stack. The full filename from the call stack is used in the output.\n\n\tfirst error\n\tgithub.com/juju/errors/annotation_test.go:193:\n\tgithub.com/juju/errors/annotation_test.go:194: annotation\n\tgithub.com/juju/errors/annotation_test.go:195:\n\tgithub.com/juju/errors/annotation_test.go:196: more context\n\tgithub.com/juju/errors/annotation_test.go:197:\n\n```go\nfunc Errorf(format string, args ...interface{}) error\n```\nErrorf creates a new annotated error and records the location that the error is created.  This should be a drop in replacement for fmt.Errorf.\n\nFor example:\n\n\treturn errors.Errorf(\"validation failed: %s\", message)\n\n```go\nfunc Forbiddenf(format string, args ...interface{}) error\n```\nForbiddenf returns an error which satistifes IsForbidden()\n\n```go\nfunc Ignore(target error, opts ...IgnoreOption)\n```\nIgnore registers target so that any error matching it (via Is) is ignored according to opts. With no opts the full ignore policy (IgnoreAsSuccess | IgnoreSilenceLog) is applied. For custom predicates see IgnoreMatch and its note on not calling back into the registry from within a matcher.\n\n```go\nfunc IgnoreMatch(match func(error) bool, opts ...IgnoreOption)\n```\nIgnoreMatch registers a custom predicate to ignore errors according to opts. A nil match is a no-op. With no opts the full ignore policy (IgnoreAsSuccess | IgnoreSilenceLog) is applied. The match function must not call back into this package's registry (Register/RegisterMatch/Classify/Ignore/IgnoreMatch/IgnoreOf), as matchers run while the registry lock is held.\n\n```go\nfunc Internalf(format string, args ...interface{}) error\n```\nInternalf returns an error which satistifes IsInternal()\n\n```go\nfunc Is(err, target error) bool\n```\n\n```go\nfunc IsAlreadyExists(err error) bool\n```\nIsAlreadyExists reports whether the error was created with AlreadyExistsf() or NewAlreadyExists().\n\n```go\nfunc IsBadRequest(err error) bool\n```\nIsBadRequest reports whether err was created with BadRequestf() or NewBadRequest().\n\n```go\nfunc IsConflict(err error) bool\n```\nIsConflict reports whether the error was created with Conflictf() or NewConflict().\n\n```go\nfunc IsForbidden(err error) bool\n```\nIsForbidden reports whether err was created with Forbiddenf() or NewForbidden().\n\n```go\nfunc IsInternal(err error) bool\n```\nIsInternal reports whether err was created with Internalf() or NewInternal().\n\n```go\nfunc IsMethodNotAllowed(err error) bool\n```\nIsMethodNotAllowed reports whether err was created with MethodNotAllowedf() or NewMethodNotAllowed().\n\n```go\nfunc IsNotAssigned(err error) bool\n```\nIsNotAssigned reports whether err was created with NotAssignedf() or NewNotAssigned().\n\n```go\nfunc IsNotFound(err error) bool\n```\nIsNotFound reports whether err was created with NotFoundf() or NewNotFound().\n\n```go\nfunc IsNotImplemented(err error) bool\n```\nIsNotImplemented reports whether err was created with NotImplementedf() or NewNotImplemented().\n\n```go\nfunc IsNotProvisioned(err error) bool\n```\nIsNotProvisioned reports whether err was created with NotProvisionedf() or NewNotProvisioned().\n\n```go\nfunc IsNotSupported(err error) bool\n```\nIsNotSupported reports whether the error was created with NotSupportedf() or NewNotSupported().\n\n```go\nfunc IsNotValid(err error) bool\n```\nIsNotValid reports whether the error was created with NotValidf() or NewNotValid().\n\n```go\nfunc IsServiceUnavailable(err error) bool\n```\nIsServiceUnavailable reports whether err was created with ServiceUnavailablef() or NewServiceUnavailable().\n\n```go\nfunc IsTimeout(err error) bool\n```\nIsTimeout reports whether err was created with Timeoutf() or NewTimeout().\n\n```go\nfunc IsTooManyRequests(err error) bool\n```\nIsTooManyRequests reports whether err was created with TooManyRequestsf() or NewTooManyRequests().\n\n```go\nfunc IsUnauthorized(err error) bool\n```\nIsUnauthorized reports whether err was created with Unauthorizedf() or NewUnauthorized().\n\n```go\nfunc Mask(other error) error\n```\nMask hides the underlying error type, and records the location of the masking.\n\n```go\nfunc Maskf(other error, format string, args ...interface{}) error\n```\nMaskf masks the given error with the given format string and arguments (like fmt.Sprintf), returning a new error that maintains the error stack, but hides the underlying error type.  The error string still contains the full annotations. If you want to hide the annotations, call Wrap.\n\n```go\nfunc MethodNotAllowedf(format string, args ...interface{}) error\n```\nMethodNotAllowedf returns an error which satisfies IsMethodNotAllowed().\n\n```go\nfunc New(message string) error\n```\nNew is a drop in replacement for the standard library errors module that records the location that the error is created.\n\nFor example:\n\n\treturn errors.New(\"validation failed\")\n\n```go\nfunc NewAlreadyExists(err error, msg string) error\n```\nNewAlreadyExists returns an error which wraps err and satisfies IsAlreadyExists().\n\n```go\nfunc NewBadRequest(err error, msg string) error\n```\nNewBadRequest returns an error which wraps err that satisfies IsBadRequest().\n\n```go\nfunc NewConflict(err error, msg string) error\n```\nNewConflict returns an error which wraps err and satisfies IsConflict().\n\n```go\nfunc NewForbidden(err error, msg string) error\n```\nNewForbidden returns an error which wraps err that satisfies IsForbidden().\n\n```go\nfunc NewInternal(err error, msg string) error\n```\nNewInternal returns an error which wraps err that satisfies IsInternal().\n\n```go\nfunc NewMethodNotAllowed(err error, msg string) error\n```\nNewMethodNotAllowed returns an error which wraps err that satisfies IsMethodNotAllowed().\n\n```go\nfunc NewNotAssigned(err error, msg string) error\n```\nNewNotAssigned returns an error which wraps err that satisfies IsNotAssigned().\n\n```go\nfunc NewNotFound(err error, msg string) error\n```\nNewNotFound returns an error which wraps err that satisfies IsNotFound().\n\n```go\nfunc NewNotImplemented(err error, msg string) error\n```\nNewNotImplemented returns an error which wraps err and satisfies IsNotImplemented().\n\n```go\nfunc NewNotProvisioned(err error, msg string) error\n```\nNewNotProvisioned returns an error which wraps err that satisfies IsNotProvisioned().\n\n```go\nfunc NewNotSupported(err error, msg string) error\n```\nNewNotSupported returns an error which wraps err and satisfies IsNotSupported().\n\n```go\nfunc NewNotValid(err error, msg string) error\n```\nNewNotValid returns an error which wraps err and satisfies IsNotValid().\n\n```go\nfunc NewServiceUnavailable(err error, msg string) error\n```\nNewServiceUnavailable returns an error which wraps err and satisfies IsServiceUnavailable().\n\n```go\nfunc NewTimeout(err error, msg string) error\n```\nNewTimeout returns an error which wraps err that satisfies IsTimeout().\n\n```go\nfunc NewTooManyRequests(err error, msg string) error\n```\nNewTooManyRequests returns an error which wraps err that satisfies IsTooManyRequests().\n\n```go\nfunc NewUnauthorized(err error, msg string) error\n```\nNewUnauthorized returns an error which wraps err and satisfies IsUnauthorized().\n\n```go\nfunc NotAssignedf(format string, args ...interface{}) error\n```\nNotAssignedf returns an error which satisfies IsNotAssigned(). Its message is the formatted text followed by \" not assigned\", so the format names the thing: NotAssignedf(\"sku %s\", sku) says \"sku cap not assigned\".\n\n```go\nfunc NotFoundf(format string, args ...interface{}) error\n```\nNotFoundf returns an error which satisfies IsNotFound(). Its message is the formatted text followed by \" not found\", so the format names the thing: NotFoundf(\"sku %s\", sku) says \"sku cap not found\".\n\n```go\nfunc NotImplementedf(format string, args ...interface{}) error\n```\nNotImplementedf returns an error which satisfies IsNotImplemented(). Its message is the formatted text followed by \" not implemented\", so the format names the thing: NotImplementedf(\"sku %s\", sku) says \"sku cap not implemented\".\n\n```go\nfunc NotProvisionedf(format string, args ...interface{}) error\n```\nNotProvisionedf returns an error which satisfies IsNotProvisioned(). Its message is the formatted text followed by \" not provisioned\", so the format names the thing: NotProvisionedf(\"sku %s\", sku) says \"sku cap not provisioned\".\n\n```go\nfunc NotSupportedf(format string, args ...interface{}) error\n```\nNotSupportedf returns an error which satisfies IsNotSupported(). Its message is the formatted text followed by \" not supported\", so the format names the thing: NotSupportedf(\"sku %s\", sku) says \"sku cap not supported\".\n\n```go\nfunc NotValidf(format string, args ...interface{}) error\n```\nNotValidf returns an error which satisfies IsNotValid(). Its message is the formatted text followed by \" not valid\", so the format names the thing: NotValidf(\"sku %s\", sku) says \"sku cap not valid\".\n\n```go\nfunc Register(target error, kind Kind)\n```\nRegister registers target so that any error matching it (via Is) is classified as kind. For custom predicates see RegisterMatch and its note on not calling back into the registry from within a matcher.\n\n```go\nfunc RegisterMatch(match func(error) bool, kind Kind)\n```\nRegisterMatch registers a custom predicate to classify errors as kind. A nil match is a no-op. The match function must not call back into this package's registry (Register/RegisterMatch/Classify/Ignore/IgnoreMatch/IgnoreOf), as matchers run while the registry lock is held.\n\n```go\nfunc ResetRegistry()\n```\nResetRegistry clears all registered matchers and ignore rules. It is intended for test teardown so a test that calls Register/RegisterMatch/Ignore/IgnoreMatch can \\`defer errors.ResetRegistry()\\` to avoid leaking global state into other tests.\n\n```go\nfunc ServiceUnavailablef(format string, args ...interface{}) error\n```\nServiceUnavailablef returns an error which satisfies IsServiceUnavailable().\n\n```go\nfunc SetSourceTrimPrefix(s string) string\n```\n\n```go\nfunc Timeoutf(format string, args ...interface{}) error\n```\nTimeoutf returns an error which satisfies IsTimeout(). Its message is the formatted text followed by \" timeout\", so the format names the thing: Timeoutf(\"sku %s\", sku) says \"sku cap timeout\".\n\n```go\nfunc TooManyRequestsf(format string, args ...interface{}) error\n```\nTooManyRequestsf returns an error which satistifes IsTooManyRequests()\n\n```go\nfunc Trace(other error) error\n```\nTrace adds the location of the Trace call to the stack.  The Cause of the resulting error is the same as the error parameter.  If the other error is nil, the result will be nil.\n\nFor example:\n\n\tif err := SomeFunc(); err != nil {\n\t    return errors.Trace(err)\n\t}\n\n```go\nfunc Unauthorizedf(format string, args ...interface{}) error\n```\nUnauthorizedf returns an error which satisfies IsUnauthorized().\n\n```go\nfunc Wrap(other, newDescriptive error) error\n```\nWrap changes the Cause of the error. The location of the Wrap call is also stored in the error stack.\n\nFor example:\n\n\tif err := SomeFunc(); err != nil {\n\t    newErr := \u0026packageError{\"more context\", private_value}\n\t    return errors.Wrap(err, newErr)\n\t}\n\n```go\nfunc Wrapf(other, newDescriptive error, format string, args ...interface{}) error\n```\nWrapf changes the Cause of the error, and adds an annotation. The location of the Wrap call is also stored in the error stack.\n\nFor example:\n\n\tif err := SomeFunc(); err != nil {\n\t    return errors.Wrapf(err, simpleErrorType, \"invalid value %q\", value)\n\t}\n\n## Types\n\n```go\ntype Err struct {\n\t// contains filtered or unexported fields\n}\n```\nErr holds a description of an error along with information about where the error was created.\n\nIt may be embedded in custom error types to add extra information that this errors package can understand.\n\n```go\nfunc NewErr(format string, args ...interface{}) Err\n```\nNewErr is used to return an Err for the purpose of embedding in other structures.  The location is not specified, and needs to be set with a call to SetLocation.\n\nFor example:\n\n\ttype FooError struct {\n\t    errors.Err\n\t    code int\n\t}\n\n\tfunc NewFooError(code int) error {\n\t    err := \u0026FooError{errors.NewErr(\"foo\"), code}\n\t    err.SetLocation(1)\n\t    return err\n\t}\n\n```go\nfunc NewErrWithCause(other error, format string, args ...interface{}) Err\n```\nNewErrWithCause is used to return an Err with cause by other error for the purpose of embedding in other structures. The location is not specified, and needs to be set with a call to SetLocation.\n\nFor example:\n\n\ttype FooError struct {\n\t    errors.Err\n\t    code int\n\t}\n\n\tfunc (e *FooError) Annotate(format string, args ...interface{}) error {\n\t    err := \u0026FooError{errors.NewErrWithCause(e.Err, format, args...), e.code}\n\t    err.SetLocation(1)\n\t    return err\n\t})\n\n```go\nfunc (e *Err) Cause() error\n```\nCause returns the most recent error in the error stack that meets one of these criteria: the original error that was raised; the new error that was passed into the Wrap function; the most recently masked error; or nil if the error itself is considered the Cause.  Normally this method is not invoked directly, but instead through the Cause stand alone function.\n\n```go\nfunc (e *Err) Error() string\n```\nError implements error.Error.\n\n```go\nfunc (e *Err) Format(s fmt.State, verb rune)\n```\nFormat implements fmt.Formatter When printing errors with %+v it also prints the stack trace. %#v unsurprisingly will print the real underlying type.\n\n```go\nfunc (e *Err) Location() (filename string, line int)\n```\nLocation is the file and line of where the error was most recently created or annotated.\n\n```go\nfunc (e *Err) Message() string\n```\nMessage returns the message stored with the most recent location. This is the empty string if the most recent call was Trace, or the message stored with Annotate or Mask.\n\n```go\nfunc (e *Err) SetLocation(callDepth int)\n```\nSetLocation records the source location of the error at callDepth stack frames above the call.\n\n```go\nfunc (e *Err) StackTrace() []string\n```\nStackTrace returns one string for each location recorded in the stack of errors. The first value is the originating error, with a line for each other annotation or tracing of the error.\n\n```go\nfunc (e *Err) Underlying() error\n```\nUnderlying returns the previous error in the error stack, if any. A client should not ever really call this method.  It is used to build the error stack and should not be introspected by client calls.  Or more specifically, clients should not depend on anything but the \\`Cause\\` of an error.\n\n```go\nfunc (e *Err) Unwrap() error\n```\nUnwrap returns the previous error in the stack, making boost typed errors transparent to stdlib errors.Is / errors.As. boost's own Cause() is single-level (the flattened root); Unwrap exposes the full chain so a wrapped sentinel (e.g. context.Canceled) stays discoverable after the error has been classified.\n\n```go\ntype IgnoreOption int\n```\nIgnoreOption is a bit flag describing how a matched error should be ignored.\n\n```go\nconst (\n\t// IgnoreAsSuccess treats the matched error as a successful outcome.\n\tIgnoreAsSuccess IgnoreOption = 1 \u003c\u003c iota\n\t// IgnoreSilenceLog suppresses logging for the matched error.\n\tIgnoreSilenceLog\n)\n```\n\n```go\nfunc IgnoreOf(err error) (IgnoreOption, bool)\n```\nIgnoreOf returns the ignore policy registered for err and whether one was found. Registered rules are evaluated in order (first match wins). A nil err returns (0, false).\n\n```go\ntype Kind int\n```\nKind is a transport-agnostic semantic classification of an error.\n\n```go\nconst (\n\tKindInternal Kind = iota // default / fallback\n\tKindNotFound\n\tKindBadRequest\n\tKindNotValid\n\tKindConflict\n\tKindAlreadyExists\n\tKindForbidden\n\tKindUnauthorized\n\tKindServiceUnavailable\n\tKindNotImplemented\n\tKindNotProvisioned\n\tKindNotSupported\n\tKindNotAssigned\n\tKindMethodNotAllowed\n\tKindTooManyRequests\n\tKindTimeout\n)\n```\n\n```go\nfunc Classify(err error) Kind\n```\nClassify returns the Kind of err. Registered matchers are evaluated in order (first match wins); if none match it falls back to builtinKind. A nil err is classified as KindInternal.\n\n","path":"github.com/xgodev/boost/model/errors","name":"errors","synopsis":"Package errors provides an easy way to annotate errors without losing the original error context.","isRedistributable":true}
