Documentation
¶
Overview ¶
Package errors provides a custom error type for out-of-bound errors.
Package errors provides a custom error type for out-of-bound errors.
Index ¶
- func Is[T error](err error) bool
- func IsErrIgnorable(err error) bool
- func IsNoError(err error) bool
- func LimitErrorMsg(err error, limit int) error
- func Max[T cmp.Ordered](a, b T) T
- func Min[T cmp.Ordered](a, b T) T
- type ErrAfter
- type ErrBefore
- type ErrExhaustedIter
- type ErrIgnorable
- type ErrInvalidRune
- type ErrNoError
- type ErrOrSol
- type ErrPanic
- type ErrPossibleError
- type ErrUnexpectedError
- type ErrUnexpectedType
- type ErrVariableError
- type ErrWhile
- type Unwrapper
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Is ¶
Is is function that checks if an error is of type T.
Parameters:
- err: The error to check.
Returns:
- bool: true if the error is of type T, false otherwise (including if the error is nil).
func IsErrIgnorable ¶
IsErrIgnorable checks if an error is an *ErrIgnorable or *ErrInvalidParameter error. If the error is nil, the function returns false.
Parameters:
- err: The error to check.
Returns:
- bool: True if the error is an *ErrIgnorable or *ErrInvalidParameter error, otherwise false.
func IsNoError ¶
IsNoError checks if an error is a no error error or if it is nil.
Parameters:
- err: The error to check.
Returns:
- bool: True if the error is a no error error or if it is nil, otherwise false.
func LimitErrorMsg ¶
LimitErrorMsg limits the error message to a certain number of unwraps. It returns the top level error for allowing to print the error message with the limit of unwraps applied.
If the error is nil or the limit is less than 0, the function does nothing.
Parameters:
- err: The error to limit.
- limit: The limit of unwraps.
Returns:
- error: The top level error with the limit of unwraps applied.
Types ¶
type ErrAfter ¶
type ErrAfter struct { // After is the element that was processed before the error occurred. After string // Reason is the reason for the error. Reason error }
ErrAfter is an error that is returned when something goes wrong after a certain element in a stream of data.
func NewErrAfter ¶
NewErrAfter creates a new ErrAfter error.
Parameters:
- after: The element that was processed before the error occurred.
- reason: The reason for the error.
Returns:
- *ErrAfter: A pointer to the new ErrAfter error.
func (*ErrAfter) ChangeReason ¶
ChangeReason implements the Unwrapper interface.
type ErrBefore ¶
type ErrBefore struct { // Before is the element that was processed before the error occurred. Before string // Reason is the reason for the error. Reason error }
ErrBefore is an error that is returned when something goes wrong before a certain element in a stream of data.
func NewErrBefore ¶
NewErrBefore creates a new ErrBefore error.
Parameters:
- before: The element that was processed before the error occurred.
- reason: The reason for the error.
Returns:
- *ErrBefore: A pointer to the new ErrBefore error.
func (*ErrBefore) ChangeReason ¶
ChangeReason implements the Unwrapper interface.
type ErrExhaustedIter ¶
type ErrExhaustedIter struct{}
ErrExhaustedIter is an error type that is returned when an iterator is exhausted (i.e., there are no more elements to consume).
func NewErrExhaustedIter ¶
func NewErrExhaustedIter() *ErrExhaustedIter
NewErrExhaustedIter creates a new ErrExhaustedIter error.
Returns:
- *ErrExhaustedIter: A pointer to the new error.
func (*ErrExhaustedIter) Error ¶
func (e *ErrExhaustedIter) Error() string
Error implements the error interface.
Message: "iterator is exhausted"
type ErrIgnorable ¶
type ErrIgnorable struct { // Err is the error that can be ignored. Err error }
ErrIgnorable represents an error that can be ignored. Useful for indicating that an error is ignorable.
func NewErrIgnorable ¶
func NewErrIgnorable(err error) *ErrIgnorable
NewErrIgnorable creates a new ErrIgnorable error.
Parameters:
- err: The error that can be ignored.
Returns:
- *ErrIgnorable: A pointer to the newly created ErrIgnorable.
func (*ErrIgnorable) ChangeReason ¶
func (e *ErrIgnorable) ChangeReason(reason error)
ChangeReason implements the Unwrapper interface.
func (*ErrIgnorable) Error ¶
func (e *ErrIgnorable) Error() string
Error implements the Unwrapper interface.
Message: "ignorable error" if the reason is nil, otherwise the error message.
func (*ErrIgnorable) Unwrap ¶
func (e *ErrIgnorable) Unwrap() error
Unwrap implements the Unwrapper interface.
type ErrInvalidRune ¶
type ErrInvalidRune struct { // Reason is the reason for the invalidity of the rune. Reason error }
ErrInvalidRune represents an error when an invalid rune is encountered.
func NewErrInvalidRune ¶
func NewErrInvalidRune(reason error) *ErrInvalidRune
NewErrInvalidRune creates a new ErrInvalidRuneAt error.
Parameters:
- reason: The reason for the invalidity of the rune.
Returns:
- *ErrInvalidRune: A pointer to the newly created ErrInvalidRune.
func (*ErrInvalidRune) ChangeReason ¶
func (e *ErrInvalidRune) ChangeReason(reason error)
ChangeReason implements the Unwrapper interface.
func (*ErrInvalidRune) Error ¶
func (e *ErrInvalidRune) Error() string
Error implements the Unwrapper interface.
Message: "invalid rune: {reason}".
However, if the reason is nil, the message is "rune is invalid" instead.
func (*ErrInvalidRune) Unwrap ¶
func (e *ErrInvalidRune) Unwrap() error
Unwrap implements the Unwrapper interface.
type ErrNoError ¶
type ErrNoError struct { // Err is the reason for the no error error. Err error }
ErrNoError represents an error when no error occurs.
func NewErrNoError ¶
func NewErrNoError(err error) *ErrNoError
NewErrNoError creates a new ErrNoError error.
Parameters:
- err: The reason for the no error error.
Returns:
- *ErrNoError: A pointer to the newly created ErrNoError.
func (*ErrNoError) ChangeReason ¶
func (e *ErrNoError) ChangeReason(reason error)
ChangeReason implements the Unwrapper interface.
func (*ErrNoError) Error ¶
func (e *ErrNoError) Error() string
Error implements the Unwrapper interface.
Message: "no error" if the reason is nil, otherwise the error message.
func (*ErrNoError) Unwrap ¶
func (e *ErrNoError) Unwrap() error
Unwrap implements the Unwrapper interface.
type ErrOrSol ¶
type ErrOrSol[T any] struct { // contains filtered or unexported fields }
ErrOrSol is a struct that holds a list of errors and a list of solutions.
func (*ErrOrSol[T]) AddAny ¶
AddAny adds an element to the list of errors or solutions if the level is greater or equal to the current level.
Parameters:
- elem: The element to add.
- level: The level of the element.
Behaviors:
- If an error has been added with a level greater than the current level, the error list is reset and the new level is updated.
- If a solution has been added with a level greater than the current level, the solution list is reset and the new level is updated.
func (*ErrOrSol[T]) AddErr ¶
AddErr adds an error to the list of errors if the level is greater or equal to the current level.
Parameters:
- err: The error to add.
- level: The level of the error.
Behaviors:
- If an error has been added with a level greater than the current level, the error list is reset and the new level is updated.
- If the error is nil, the ignoreErr flag is set to true and the error list is reset.
func (*ErrOrSol[T]) AddSol ¶
AddSol adds a solution to the list of solutions if the level is greater or equal to the current level.
Parameters:
- sol: The solution to add.
- level: The level of the solution.
Behaviors:
- If a solution has been added with a level greater than the current level, the solution list is reset and the new level is updated.
- This function sets the ignoreErr flag to true and resets the error list.
func (*ErrOrSol[T]) Errors ¶ added in v0.1.6
Errors returns the list of errors.
Returns:
- []error: The list of errors.
type ErrPanic ¶
type ErrPanic struct { // Value is the value that caused the panic. Value any }
ErrPanic represents an error when a panic occurs.
func NewErrPanic ¶
NewErrPanic creates a new ErrPanic error.
Parameters:
- value: The value that caused the panic.
Returns:
- *ErrPanic: A pointer to the newly created ErrPanic.
type ErrPossibleError ¶
type ErrPossibleError struct { // Reason is the reason for the possible error. Reason error // Possible is the possible error. Possible error }
ErrPossibleError represents an error that occurs when a possible error is encountered.
func NewErrPossibleError ¶
func NewErrPossibleError(reason error, possible error) *ErrPossibleError
NewErrPossibleError creates a new ErrPossibleError error.
Parameters:
- reason: The reason for the possible error.
- possible: The possible error.
Returns:
- *ErrPossibleError: A pointer to the new ErrPossibleError error.
func (*ErrPossibleError) ChangeReason ¶
func (e *ErrPossibleError) ChangeReason(reason error)
ChangeReason implements the Unwrapper interface.
func (*ErrPossibleError) Error ¶
func (e *ErrPossibleError) Error() string
Error implements the Unwrapper interface.
Message: "{reason}. It is possible that {possible}".
However, if the reason is nil, the message is "no error occurred. It is possible that {possible}" instead.
If the possible error is nil, the "It is possible that {possible}" part is omitted.
func (*ErrPossibleError) Unwrap ¶
func (e *ErrPossibleError) Unwrap() error
Unwrap implements the Unwrapper interface.
type ErrUnexpectedError ¶
type ErrUnexpectedError struct { // Reason is the reason for the unexpected error. Reason error }
ErrUnexpectedError represents an error that occurs unexpectedly.
func NewErrUnexpectedError ¶
func NewErrUnexpectedError(reason error) *ErrUnexpectedError
NewErrUnexpectedError creates a new ErrUnexpectedError error.
Parameters:
- reason: The reason for the unexpected error.
Returns:
- *ErrUnexpectedError: A pointer to the new ErrUnexpectedError error.
func (*ErrUnexpectedError) ChangeReason ¶
func (e *ErrUnexpectedError) ChangeReason(reason error)
ChangeReason implements the Unwrapper interface.
func (*ErrUnexpectedError) Error ¶
func (e *ErrUnexpectedError) Error() string
Error implements the Unwrapper interface.
Message: "unexpected error: {reason}".
However, if the reason is nil, the message is "unexpected error" instead.
func (*ErrUnexpectedError) Unwrap ¶
func (e *ErrUnexpectedError) Unwrap() error
Unwrap implements the Unwrapper interface.
type ErrUnexpectedType ¶
type ErrUnexpectedType[T any] struct { // Elem is the element that caused the error. Elem T // Kind is the category of the type that was expected. Kind string }
ErrUnexpectedType represents an error when a value has an invalid type.
func NewErrUnexpectedType ¶
func NewErrUnexpectedType[T any](kind string, elem T) *ErrUnexpectedType[T]
NewErrUnexpectedType creates a new ErrUnexpectedType error.
Parameters:
- typeName: The name of the type that was expected.
- elem: The element that caused the error.
Returns:
- *ErrUnexpectedType: A pointer to the newly created ErrUnexpectedType.
func (*ErrUnexpectedType[T]) Error ¶
func (e *ErrUnexpectedType[T]) Error() string
Error implements the error interface.
Message: "type <type> is not a valid <kind> type"
type ErrVariableError ¶
type ErrVariableError struct { // Variable is the name of the variable that caused the error. Variable string // Reason is the reason for the variable error. Reason error }
ErrVariableError represents an error that occurs when a variable is invalid.
func NewErrVariableError ¶
func NewErrVariableError(variable string, reason error) *ErrVariableError
NewErrVariableError creates a new ErrVariableError error.
Parameters:
- variable: The name of the variable that caused the error.
- reason: The reason for the variable error.
Returns:
- *ErrVariableError: A pointer to the new ErrVariableError error.
func (*ErrVariableError) ChangeReason ¶
func (e *ErrVariableError) ChangeReason(reason error)
ChangeReason implements the Unwrapper interface.
func (*ErrVariableError) Error ¶
func (e *ErrVariableError) Error() string
Error implements the Unwrapper interface.
Message: "variable ({variable}) error: {reason}".
However, if the reason is nil, the message is "variable ({variable}) error" instead.
func (*ErrVariableError) Unwrap ¶
func (e *ErrVariableError) Unwrap() error
Unwrap implements the Unwrapper interface.
type ErrWhile ¶
type ErrWhile struct { // Operation is the operation that was being performed. Operation string // Reason is the reason for the error. Reason error }
ErrWhile represents an error that occurs while performing an operation.
func NewErrWhile ¶
NewErrWhile creates a new ErrWhile error.
Parameters:
- operation: The operation that was being performed.
- reason: The reason for the error.
Returns:
- *ErrWhile: A pointer to the newly created ErrWhile.
func (*ErrWhile) ChangeReason ¶
ChangeReason implements the Unwrapper interface.
type Unwrapper ¶
type Unwrapper interface { // Unwrap returns the error that this error wraps. // // Returns: // - error: The error that this error wraps. Unwrap() error // ChangeReason changes the reason of the error. // // Parameters: // - reason: The new reason of the error. ChangeReason(reason error) }
Unwrapper is an interface that defines a method to unwrap an error.