Documentation
¶
Index ¶
- Variables
- type Error
- func New(errType Type, message string, opts ...Option) Error
- func NewAboveLimit(name string, max int) Error
- func NewBelowLimit(name string, min int) Error
- func NewEquals(name string, invalidVals ...string) Error
- func NewInvalidFormat(name, format string) Error
- func NewInvalidLength(name string, expLen int) Error
- func NewMissingValue(name string) Error
- func NewNotEquals(name, exp string) Error
- func NewNotOneOf(name string, values ...string) Error
- func NewResourceAlreadyExists[T any]() Error
- func NewResourceNotFound[T any]() Error
- type Option
- type Type
- type Unwrapper
Constants ¶
This section is empty.
Variables ¶
var ( // ErrResourceNotFound is returned when the resource is not found. ErrResourceNotFound = errors.New("resource not found") // ErrResourceAlreadyExists is returned when the resource already exists. ErrResourceAlreadyExists = errors.New("resource already exists") // ErrInvalidFormat is returned when the format is invalid. ErrInvalidFormat = errors.New("invalid format") // ErrMissingValue is returned when the value is missing. ErrMissingValue = errors.New("missing value") )
Functions ¶
This section is empty.
Types ¶
type Error ¶
type Error struct {
// Type the type of the [Error].
Type Type
// InternalCode is a code generated by the system to identify errors.
//
// This helps external systems, calling the local system, to differentiate errors with the same [Type].
InternalCode string
// Message a clear explanation about the occurrence (i.e. an [Error]).
Message string
// StaticError is the static error [Error] is attached to.
//
// Consider [Error] as a dynamic error as the latter holds values that can be modified at any time without
// needing to re-allocate another [Error] instance.
//
// This field may also work as parent error.
StaticError error
// Metadata is a collection of information additional to the properties defined in [Error].
// These properties are dynamic and external systems should not depend on its formatting nor values.
Metadata map[string]string
}
An Error refers to an issue or malfunction that occurs within the operating system or other system-level software, which impacts the proper execution of a program. These errors typically arise from interactions between the application and the underlying hardware or operating system resources.
If New is called to create the Error, use Option routines (e.g. WithInternalCode, WithStaticError) to set optional values.
This structure implements stdlib error, errors.Unwrap and fmt.Stringer interfaces.
func NewAboveLimit ¶
NewAboveLimit allocates a new Error.
Specifies Error properties for `value is above the expected limit` error cases.
func NewBelowLimit ¶
NewBelowLimit allocates a new Error.
Specifies Error properties for `value is below the expected limit` error cases.
func NewEquals ¶
NewEquals allocates a new Error.
Specifies Error properties for `value is equals to` error cases.
func NewInvalidFormat ¶
NewInvalidFormat allocates a new Error.
Specifies Error properties for `invalid format` error cases.
func NewInvalidLength ¶
NewInvalidLength allocates a new Error.
Specifies Error properties for `value does not have the expected length` error cases.
func NewMissingValue ¶
NewMissingValue allocates a new Error.
Specifies Error properties for `missing value` error cases.
func NewNotEquals ¶
NewNotEquals allocates a new Error.
Specifies Error properties for `value is not equals to` error cases.
func NewNotOneOf ¶
NewNotOneOf allocates a new Error.
Specifies Error properties for `value is not one of` error cases.
func NewResourceAlreadyExists ¶
NewResourceAlreadyExists allocates a new Error.
Specifies Error properties for `resource already exists` error cases.
func NewResourceNotFound ¶
NewResourceNotFound allocates a new Error.
Specifies Error properties for `resource not found` error cases.
func (Error) Unwrap ¶
Unwrap unwraps an underlying static error based on [Error.StaticError].
If given field is nil, a new static error will be generated using errors.New and the [Error.Message].
type Option ¶
type Option func(*Error)
Option is an option routine exposed to clients to set optional values of Error.
func WithInfo ¶
WithInfo appends `key` and `value` into the [Error.Metadata] collection.
If `key` is empty, no entry will be set.
func WithInternalCode ¶
WithInternalCode sets the Error internal code.
type Type ¶
type Type uint16
Type is a custom integer representing Error types.
const ( // UnknownCode the error code is not known. UnknownCode Type = iota // OutOfRange the value is out of the specified range. OutOfRange // InvalidArgument the value is invalid according to internal rules. InvalidArgument // MissingPrecondition a precondition is required to be executed. MissingPrecondition // FailedPrecondition a required precondition was executed, but it resulted in failure. FailedPrecondition // ResourceExists the resource already exist in a persistence store. ResourceExists // ResourceNotFound the resource was not present in a persistence store. ResourceNotFound // PermissionDenied access to a certain operation -or resource- was denied. PermissionDenied // Unauthenticated the given routine requires the caller (aka. Principal) to be authenticated, yet // no authentication was found. Unauthenticated // Aborted the routine execution was aborted. Aborted // ResourceExhausted the system cannot handle more calls at this time. ResourceExhausted // DeadlineExceeded the routine execution could not respond in time, reaching the caller wait deadline. DeadlineExceeded // Unimplemented the operation has not been implemented yet. Unimplemented // DataLoss the operation resulted in data missing. DataLoss Unavailable // Internal a non-public error happened during the routine execution. Internal )
type Unwrapper ¶
type Unwrapper interface {
// Unwrap retrieves the slice of errors.
Unwrap() []error
}
Unwrapper is construct holding a set of errors.
Its main usage is by casting this from an error interface to retrieve the slice of errors joined with errors.Join (or any structure implementing errors.Unwrap).