Documentation
¶
Index ¶
- Constants
- Variables
- func Is(err, target error) bool
- func NewMissingRequiredDependency(name string) error
- func NewValidationError(desc string) error
- func Retryable(err error) bool
- func RootError(err error) string
- func Stack(err error) []runtime.StackFrame
- type CodeType
- type CustomError
- func (ce CustomError) Error() string
- func (ce CustomError) Retryable(retryable bool) CustomError
- func (ce CustomError) WithCode(code CodeType) CustomError
- func (ce CustomError) WithKind(kind KindType) CustomError
- func (ce CustomError) WithRootError(err error) CustomError
- func (ce CustomError) WithStack() CustomError
- type KindType
Constants ¶
const ( // CodeUnknown is the default code returned when the application doesn't attach any code into the error. CodeUnknown CodeType = "UNKNOWN" // KindUnexpected is the default kind returned when the application doesn't attach any kind into the error. KindUnexpected KindType = "UNEXPECTED" // KindConflict are errors caused by requests with data that conflicts with the current state of the system. KindConflict KindType = "CONFLICT" // KindInternal are errors caused by some internal fail like failed IO calls or invalid memory states. KindInternal KindType = "INTERNAL" // KindInvalidInput are errors caused by some invalid values on the input. KindInvalidInput KindType = "INVALID_INPUT" // KindNotFound are errors caused by any required resources that not exists on the data repository. KindNotFound KindType = "NOT_FOUND" // KindUnauthenticated are errors caused by an unauthenticated call. KindUnauthenticated KindType = "UNAUTHENTICATED" KindUnauthorized KindType = "UNAUTHORIZED" // KindResourceExhausted indicates some resource has been exhausted, perhaps a per-user quota, or perhaps the entire file system is out of space. KindResourceExhausted KindType = "RESOURCE_EXHAUSTED" )
Variables ¶
var ( // ErrResourceNotFound indicates that a desired resource was not found. ErrResourceNotFound error = New("resource not found").WithKind(KindNotFound).WithCode("RESOURCE_NOT_FOUND") // ErrNotImplemented indicates that a given feature is not implemented yet. ErrNotImplemented error = New("feature not implemented yet").WithCode("FEATURE_NOT_IMPLEMENTED") // ErrMock is a fake mocked that should be used in test scenarios. ErrMock error = New("mocked error").WithCode("MOCKED_ERROR") )
Functions ¶
func NewMissingRequiredDependency ¶
NewMissingRequiredDependency creates a new error that indicates a missing required dependency. It should be producing at struct constructors.
func NewValidationError ¶
NewValidationError creates a Validation error.
func Retryable ¶
Retryable this method receives an error, then compares its interface type with the CustomError interface. If the interfaces types matches, returns if the error is Retryable.
func RootError ¶
RootError tries to convert the given error into a CustomError. If so, it recursively tries to find the root error (non CustomError) in a CustomError RootError chain and returns its message.
func Stack ¶ added in v1.2.0
func Stack(err error) []runtime.StackFrame
Stack this method receives an error, then compares its interface type with the CustomError interface. If the interfaces types matches, returns its Stack Trace.
Types ¶
type CustomError ¶
type CustomError struct {
// contains filtered or unexported fields
}
CustomError is a structure that encodes useful information about a given error. It's supposed to flow within the application in detriment of the the default golang error, since its Kind and Code attributes are the keys to express its semantic and uniqueness, respectively. It should be generated once by the peace of code that found the error (because it's where we have more context about the error), and be by passed to the upper layers of the application.
func New ¶
func New(message string, args ...interface{}) CustomError
New returns a new instance of CustomError with the given message.
func (CustomError) Retryable ¶
func (ce CustomError) Retryable(retryable bool) CustomError
Retryable returns a copy of the CustomError tagged as retryable or not.
func (CustomError) WithCode ¶
func (ce CustomError) WithCode(code CodeType) CustomError
WithCode return a copy of the CustomError with the given CodeType filled.
func (CustomError) WithKind ¶
func (ce CustomError) WithKind(kind KindType) CustomError
WithKind return a copy of the CustomError with the given KindType filled.
func (CustomError) WithRootError ¶
func (ce CustomError) WithRootError(err error) CustomError
WithRootError returns a copy of the CustomError with the RootError filled.
func (CustomError) WithStack ¶ added in v1.2.0
func (ce CustomError) WithStack() CustomError
WithStack returns a copy of the CustomError tagged as retryable or not.