Errors

package
v0.2.43 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 19, 2024 License: MIT Imports: 9 Imported by: 8

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.

Package errors provides a custom error type for out-of-bound errors.

Index

Constants

View Source
const (
	// DefaultLFPermissions is the default file permissions for creating a log file.
	DefaultLFPermissions fs.FileMode = 0666

	// DefaultLFExtension is the default file extension for creating a log file.
	DefaultLFExtension string = ".log.md"

	// DefaultLFFlags is the default flags for creating a log file.
	DefaultLFFlags int = os.O_CREATE | os.O_WRONLY | os.O_APPEND

	// DefaultLoggerFlags is the default flags for creating a logger.
	DefaultLoggerFlags int = log.LstdFlags | log.Llongfile
)

Variables

This section is empty.

Functions

func As added in v0.2.32

func As[T any](err error) bool

As is function that checks if an error is of type T.

If the error is nil, the function returns false.

Parameters:

  • err: The error to check.

Returns:

  • bool: true if the error is of type T, false otherwise.

func IsErrIgnorable

func IsErrIgnorable(err error) bool

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

func IsNoError(err error) bool

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 added in v0.2.34

func LimitErrorMsg(err error, limit int) error

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 added in v0.2.34

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 added in v0.2.34

func NewErrAfter(after string, reason error) *ErrAfter

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 added in v0.2.34

func (e *ErrAfter) ChangeReason(reason error)

ChangeReason changes the reason for the error.

Parameters:

  • reason: The new reason for the error.

func (*ErrAfter) Error added in v0.2.34

func (e *ErrAfter) Error() string

Error is a method of the error interface.

Returns:

  • string: The error message.

func (*ErrAfter) Unwrap added in v0.2.34

func (e *ErrAfter) Unwrap() error

Unwrap returns the reason for the error. It is used for error unwrapping.

Returns:

  • error: The reason for the error.

type ErrAt added in v0.2.33

type ErrAt struct {
	// Index is the index where the error occurred.
	Index int

	// Reason is the reason for the error.
	Reason error
}

ErrAt represents an error that occurs at a specific index.

func NewErrAt added in v0.2.33

func NewErrAt(index int, reason error) *ErrAt

NewErrAt creates a new ErrAt error.

Parameters:

  • index: The index where the error occurred.
  • reason: The reason for the error.

Returns:

  • *ErrAt: A pointer to the newly created ErrAt.

func (*ErrAt) ChangeReason added in v0.2.34

func (e *ErrAt) ChangeReason(reason error)

ChangeReason changes the reason for the error.

Parameters:

  • reason: The new reason for the error.

func (*ErrAt) Error added in v0.2.33

func (e *ErrAt) Error() string

Error is a method of the error interface that returns the error message.

If the reason is not provided (nil), the error message is "at index %d: something went wrong".

Returns:

  • string: The error message.

func (*ErrAt) Unwrap added in v0.2.33

func (e *ErrAt) Unwrap() error

Unwrap returns the reason for the error. It is used for error unwrapping.

Returns:

  • error: The reason for the error.

type ErrBefore added in v0.2.34

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 added in v0.2.34

func NewErrBefore(before string, reason error) *ErrBefore

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 added in v0.2.34

func (e *ErrBefore) ChangeReason(reason error)

ChangeReason changes the reason for the error.

Parameters:

  • reason: The new reason for the error.

func (*ErrBefore) Error added in v0.2.34

func (e *ErrBefore) Error() string

Error is a method of the error interface.

Returns:

  • string: The error message.

func (*ErrBefore) Unwrap added in v0.2.34

func (e *ErrBefore) Unwrap() error

Unwrap returns the reason for the error. It is used for error unwrapping.

Returns:

  • error: The reason for the error.

type ErrEmpty added in v0.2.43

type ErrEmpty[T any] struct {
	// Value is the value that caused the error.
	Value T
}

ErrEmpty represents an error when a value is empty.

func NewErrEmpty added in v0.2.43

func NewErrEmpty[T any](value T) *ErrEmpty[T]

NewErrEmpty creates a new ErrEmpty error.

Parameters:

  • value: The value that caused the error.

Returns:

  • *ErrEmpty: A pointer to the newly created ErrEmpty.

func (*ErrEmpty[T]) Error added in v0.2.43

func (e *ErrEmpty[T]) Error() string

Error returns the error message: "value must not be empty".

Returns:

  • string: The error message.

func (*ErrEmpty[T]) ErrorIf added in v0.2.43

func (e *ErrEmpty[T]) ErrorIf() error

ErrorIf returns the error if the target value is empty.

Parameters:

  • empty: A function that returns true if the target value is empty.

Returns:

  • error: The error if the target value is empty, nil otherwise.

type ErrGT added in v0.2.32

type ErrGT struct {
	// Value is the value that caused the error.
	Value int
}

ErrGT represents an error when a value is less than or equal to a specified value.

func NewErrGT added in v0.2.32

func NewErrGT(value int) *ErrGT

NewErrGT creates a new ErrGT error with the specified value.

Parameters:

  • value: The minimum value that is not allowed.

Returns:

  • *ErrGT: A pointer to the newly created ErrGT.

func (*ErrGT) Error added in v0.2.32

func (e *ErrGT) Error() string

Error returns the error message: "value must be greater than <value>"

Returns:

  • string: The error message.

Behaviors:

  • If the value is 0, the error message is "value must be positive".

func (*ErrGT) ErrorIf added in v0.2.43

func (e *ErrGT) ErrorIf(target int) error

ErrorIf returns the error if the target value is less than or equal to the specified value.

Parameters:

  • target: The value to check.

Returns:

  • error: The error if the target value is less than or equal to the specified value, nil otherwise.

type ErrGTE added in v0.2.32

type ErrGTE struct {
	// Value is the value that caused the error.
	Value int
}

ErrGTE represents an error when a value is less than a specified value.

func NewErrGTE added in v0.2.32

func NewErrGTE(value int) *ErrGTE

NewErrGTE creates a new ErrGTE error with the specified value.

Parameters:

  • value: The minimum value that is allowed.

Returns:

  • *ErrGTE: A pointer to the newly created ErrGTE.

func (*ErrGTE) Error added in v0.2.32

func (e *ErrGTE) Error() string

Error returns the error message: "value must be greater than or equal to <value>"

Returns:

  • string: The error message.

Behaviors:

  • If the value is 0, the error message is "value must be non-negative".

func (*ErrGTE) ErrorIf added in v0.2.43

func (e *ErrGTE) ErrorIf(target int) error

ErrorIf returns the error if the target value is less than the specified value.

Parameters:

  • target: The value to check.

Returns:

  • error: The error if the target value is less than the specified value, nil otherwise.

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 added in v0.2.34

func (e *ErrIgnorable) ChangeReason(reason error)

ChangeReason changes the reason for the ignorable error.

Parameters:

  • reason: The new reason for the ignorable error.

func (*ErrIgnorable) Error

func (e *ErrIgnorable) Error() string

Error is a method of the error interface. It does not mention that the error is ignorable.

Returns:

  • string: The error message of the ignorable error (no mention of being ignorable).

func (*ErrIgnorable) Unwrap

func (e *ErrIgnorable) Unwrap() error

Unwrap returns the error that can be ignored. It is used for error unwrapping.

Returns:

  • error: The error that can be ignored.

type ErrInvalidCall

type ErrInvalidCall struct {
	// FnName is the name of the function.
	FnName string

	// Signature is the Signature of the function.
	Signature reflect.Type

	// Reason is the Reason for the failure.
	Reason error
}

ErrInvalidCall represents an error that occurs when a function is not called correctly.

func NewErrInvalidCall

func NewErrInvalidCall(functionName string, function any, reason error) *ErrInvalidCall

NewErrInvalidCall creates a new ErrInvalidCall. If the reason is not provided (nil), the reason is set to "an error occurred while calling the function" by default.

Parameters:

  • functionName: The name of the function.
  • function: The function that failed.
  • reason: The reason for the failure.

Returns:

  • *ErrInvalidCall: A pointer to the new ErrInvalidCall.

func (*ErrInvalidCall) ChangeReason added in v0.2.34

func (e *ErrInvalidCall) ChangeReason(reason error)

ChangeReason changes the reason for the failure of the function call.

Parameters:

  • reason: The new reason for the failure.

func (*ErrInvalidCall) Error

func (e *ErrInvalidCall) Error() string

Error is a method of the error interface.

Returns:

  • string: The error message.

func (*ErrInvalidCall) Unwrap

func (e *ErrInvalidCall) Unwrap() error

Unwrap returns the underlying error that caused the ErrInvalidCall. It is used for error unwrapping.

Returns:

  • error: The reason for the failure.

type ErrInvalidCharacter added in v0.2.39

type ErrInvalidCharacter struct {
	// Character is the invalid character.
	Character rune
}

ErrInvalidCharacter represents an error when an invalid character is found.

func NewErrInvalidCharacter added in v0.2.39

func NewErrInvalidCharacter(character rune) *ErrInvalidCharacter

NewErrInvalidCharacter creates a new ErrInvalidCharacter error.

Parameters:

  • character: The invalid character.

Returns:

  • *ErrInvalidCharacter: A pointer to the newly created ErrInvalidCharacter.

func (*ErrInvalidCharacter) Error added in v0.2.39

func (e *ErrInvalidCharacter) Error() string

Error returns the error message: "character (<character>) is invalid".

Returns:

  • string: The error message.

type ErrInvalidParameter

type ErrInvalidParameter struct {
	// Parameter is the name of the Parameter.
	Parameter string

	// Reason is the Reason for the invalidity of the parameter.
	Reason error
}

ErrInvalidParameter represents an error when a parameter is invalid.

func NewErrInvalidParameter

func NewErrInvalidParameter(parameter string, reason error) *ErrInvalidParameter

NewErrInvalidParameter creates a new ErrInvalidParameter error. If the reason is not provided (nil), the reason is set to "parameter is invalid" by default.

Parameters:

  • parameter: The name of the parameter.
  • reason: The reason for the invalidity.

Returns:

  • error: A pointer to the newly created ErrInvalidParameter.

func NewErrNilParameter

func NewErrNilParameter(parameter string) *ErrInvalidParameter

ErrNilParameter represents an error when a parameter is nil. This is a shorthand for NewErrInvalidParameter(parameter, NewErrNilValue()).

Parameters:

  • parameter: The name of the parameter.

Returns:

  • *ErrInvalidParameter: A pointer to the newly created ErrInvalidParameter.

func (*ErrInvalidParameter) ChangeReason added in v0.2.34

func (e *ErrInvalidParameter) ChangeReason(reason error)

ChangeReason changes the reason for the invalidity of the parameter.

Parameters:

  • reason: The new reason for the invalidity of the parameter.

func (*ErrInvalidParameter) Error

func (e *ErrInvalidParameter) Error() string

Error is a method of the error interface.

If the reason is not provided (nil), no reason is included in the error message.

Returns:

  • string: The error message.

func (*ErrInvalidParameter) Unwrap

func (e *ErrInvalidParameter) Unwrap() error

Unwrap returns the reason for the invalidity of the parameter. It is used for error unwrapping.

Returns:

  • error: The reason for the invalidity of the parameter.

type ErrInvalidRune added in v0.2.33

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 added in v0.2.33

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 added in v0.2.34

func (e *ErrInvalidRune) ChangeReason(reason error)

ChangeReason changes the reason for the invalidity of the rune.

Parameters:

  • reason: The new reason for the invalidity of the rune.

func (*ErrInvalidRune) Error added in v0.2.33

func (e *ErrInvalidRune) Error() string

Error is a method of the error interface that returns the error message.

If the reason is not provided (nil), no reason is included in the error message.

Returns:

  • string: The error message.

func (*ErrInvalidRune) Unwrap added in v0.2.33

func (e *ErrInvalidRune) Unwrap() error

Unwrap returns the reason for the invalidity of the rune. It is used for error unwrapping.

Returns:

  • error: The reason for the invalidity of the rune.

type ErrInvalidUsage added in v0.2.34

type ErrInvalidUsage struct {
	// Reason is the reason for the invalid usage.
	Reason error

	// Usage is the usage of the function.
	Usage string
}

ErrInvalidUsage represents an error that occurs when a function is used incorrectly.

func NewErrInvalidUsage added in v0.2.34

func NewErrInvalidUsage(reason error, usage string) *ErrInvalidUsage

NewErrInvalidUsage creates a new ErrInvalidUsage error.

Parameters:

  • reason: The reason for the invalid usage.
  • usage: The usage of the function.

Returns:

  • *ErrInvalidUsage: A pointer to the new ErrInvalidUsage error.

func (*ErrInvalidUsage) ChangeReason added in v0.2.34

func (e *ErrInvalidUsage) ChangeReason(reason error)

ChangeReason changes the reason for the invalid usage.

Parameters:

  • reason: The new reason for the invalid usage.

func (*ErrInvalidUsage) Error added in v0.2.34

func (e *ErrInvalidUsage) Error() string

Error is a method of the error interface.

Returns:

  • string: The error message.

func (*ErrInvalidUsage) Unwrap added in v0.2.34

func (e *ErrInvalidUsage) Unwrap() error

Unwrap returns the reason for the invalid usage. It is used for error unwrapping.

Returns:

  • error: The reason for the invalid usage.

type ErrInvalidValues added in v0.2.43

type ErrInvalidValues[T comparable] struct {
	// Values is the list of invalid values.
	Values []T
}

ErrInvalidValues represents an error when a value is in a list of invalid values.

func NewErrInvalidValues added in v0.2.43

func NewErrInvalidValues[T comparable](values []T) *ErrInvalidValues[T]

NewErrInvalidValues creates a new ErrInvalidValues error.

Parameters:

  • values: The list of invalid values.

Returns:

  • *ErrInvalidValues: A pointer to the newly created ErrInvalidValues.

func NewErrUnexpectedValue added in v0.2.43

func NewErrUnexpectedValue[T comparable](value T) *ErrInvalidValues[T]

NewErrUnexpectedValue is a function that creates a new ErrInvalidValues error.

Parameters:

  • value: The value that was unexpected.

Returns:

  • *ErrInvalidValues: A pointer to the newly created ErrInvalidValues.

func (*ErrInvalidValues[T]) Error added in v0.2.43

func (e *ErrInvalidValues[T]) Error() string

Error returns the error message: "value must not be <values>" according to the following format:

<value 0>, <value 1>, <value 2>, ..., or <value n>

Returns:

  • string: The error message.

Behaviors:

  • If there are no values, the error message is "value is invalid".
  • If there is one value, the error message is "value must not be <value 0>".
  • If there are two values, the error message is "value must not be either <value 0> or <value 1>".

func (*ErrInvalidValues[T]) ErrorIf added in v0.2.43

func (e *ErrInvalidValues[T]) ErrorIf(target T) error

ErrorIf returns the error if the target value is in the list of invalid values.

Parameters:

  • equals: A function that returns true if the target value is equal to the value in the list of invalid values.

Returns:

  • error: The error if the target value is in the list of invalid values, nil otherwise.

type ErrLT added in v0.2.32

type ErrLT struct {
	// Value is the value that caused the error.
	Value int
}

ErrLT represents an error when a value is greater than or equal to a specified value.

func NewErrLT added in v0.2.32

func NewErrLT(value int) *ErrLT

NewErrLT creates a new ErrLT error with the specified value.

Parameters:

  • value: The maximum value that is not allowed.

Returns:

  • *ErrLT: A pointer to the newly created ErrLT.

func (*ErrLT) Error added in v0.2.32

func (e *ErrLT) Error() string

Error returns the error message: "value must be less than <value>"

Returns:

  • string: The error message.

Behaviors:

  • If the value is 0, the error message is "value must be negative".

func (*ErrLT) ErrorIf added in v0.2.43

func (e *ErrLT) ErrorIf(target int) error

ErrorIf returns the error if the target value is greater than or equal to the specified value.

Parameters:

  • target: The value to check.

Returns:

  • error: The error if the target value is greater than or equal to the specified value, nil otherwise.

type ErrLTE added in v0.2.32

type ErrLTE struct {
	// Value is the value that caused the error.
	Value int
}

ErrLTE represents an error when a value is greater than a specified value.

func NewErrLTE added in v0.2.32

func NewErrLTE(value int) *ErrLTE

NewErrLTE creates a new ErrLTE error with the specified value.

Parameters:

  • value: The maximum value that is allowed.

Returns:

  • *ErrLTE: A pointer to the newly created ErrLTE.

func (*ErrLTE) Error added in v0.2.32

func (e *ErrLTE) Error() string

Error returns the error message: "value must be less than or equal to <value>"

Returns:

  • string: The error message.

Behaviors:

  • If the value is 0, the error message is "value must be non-positive".

func (*ErrLTE) ErrorIf added in v0.2.43

func (e *ErrLTE) ErrorIf(target int) error

ErrorIf returns the error if the target value is greater than the specified value.

Parameters:

  • target: The value to check.

Returns:

  • error: The error if the target value is greater than the specified value, nil otherwise.

type ErrNilValue added in v0.2.39

type ErrNilValue struct{}

ErrNilValue represents an error when a value is nil.

func NewErrNilValue added in v0.2.39

func NewErrNilValue() *ErrNilValue

NewErrNilValue creates a new ErrNilValue error.

Returns:

  • *ErrNilValue: The new ErrNilValue error.

func (*ErrNilValue) Error added in v0.2.39

func (e *ErrNilValue) Error() string

Error returns the error message: "value must not be nil".

Returns:

  • string: The error message.

func (*ErrNilValue) ErrorIf added in v0.2.43

func (e *ErrNilValue) ErrorIf(target any) error

ErrorIf returns the error if the target value is nil.

Parameters:

  • target: The value to check.

Returns:

  • error: The error if the target value is nil, nil otherwise.

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 added in v0.2.34

func (e *ErrNoError) ChangeReason(reason error)

ChangeReason changes the reason of the no error error.

Parameters:

  • reason: The new reason for the no error error.

func (*ErrNoError) Error

func (e *ErrNoError) Error() string

Error is a method of the error interface.

Returns:

  • string: The error message of the no error error (no mention of being a no error error).

func (*ErrNoError) ErrorIf added in v0.2.43

func (e *ErrNoError) ErrorIf() error

ErrorIf is a method of that returns the error if the error is not nil.

Returns:

  • error: The error if the error is not nil, nil otherwise.

func (*ErrNoError) Unwrap

func (e *ErrNoError) Unwrap() error

Unwrap is a method of the errors interface.

Returns:

  • error: The reason for the no error error.

type ErrNotComparable added in v0.2.39

type ErrNotComparable[T any] struct {
	// Value is the value that caused the error.
	Value T
}

ErrNotComparable represents an error when a value is not comparable.

func NewErrNotComparable added in v0.2.39

func NewErrNotComparable[T any](value T) *ErrNotComparable[T]

NewErrNotComparable creates a new ErrNotComparable error.

Returns:

  • *ErrNotComparable: A pointer to the newly created ErrNotComparable.

func (*ErrNotComparable[T]) Error added in v0.2.39

func (e *ErrNotComparable[T]) Error() string

Error returns the error message: "type <type> does not support comparison".

Returns:

  • string: The error message.

func (*ErrNotComparable[T]) ErrorIf added in v0.2.43

func (e *ErrNotComparable[T]) ErrorIf() error

ErrorIf returns the error if the target value is not comparable.

Returns:

  • error: The error if the target value is not comparable, nil otherwise.

type ErrOutOfBounds

type ErrOutOfBounds struct {
	// LowerBound and UpperBound are the lower and upper bounds of the range,
	// respectively.
	LowerBound, UpperBound int

	// LowerInclusive and UpperInclusive are flags indicating whether the lower
	// and upper bounds are inclusive, respectively.
	LowerInclusive, UpperInclusive bool

	// Value is the value that caused the error.
	Value int
}

ErrOutOfBounds represents an error when a value is out of a specified range.

func NewErrOutOfBounds

func NewErrOutOfBounds(value int, lowerBound, upperBound int) *ErrOutOfBounds

NewOutOfBounds creates a new ErrOutOfBound error. If no inclusivity flags are provided, the lower bound is inclusive and the upper bound is exclusive.

Parameters:

  • lowerBound, upperbound: The lower and upper bounds of the range, respectively.
  • value: The value that caused the error.

Returns:

  • *ErrOutOfBounds: A pointer to the newly created ErrOutOfBound.

func (*ErrOutOfBounds) Error

func (e *ErrOutOfBounds) Error() string

Error is a method of the error interface.

The format of the error message is as follows:

value (value) not in range [lowerBound, upperBound]

The square brackets indicate that the lower bound is inclusive, while the parentheses indicate that the upper bound is exclusive.

Returns:

  • string: The error message of the out-of-bound error.

func (*ErrOutOfBounds) ErrorIf added in v0.2.43

func (e *ErrOutOfBounds) ErrorIf() error

ErrorIf returns the error if the value is out of the specified range.

Returns:

  • error: The error if the value is out of the specified range, nil otherwise.

func (*ErrOutOfBounds) WithLowerBound

func (e *ErrOutOfBounds) WithLowerBound(isInclusive bool) *ErrOutOfBounds

WithLowerBound sets the inclusivity of the lower bound.

Parameters:

  • isInclusive: A boolean indicating whether the lower bound is inclusive.

Returns:

  • *ErrOutOfBound: The error instance for chaining.

func (*ErrOutOfBounds) WithUpperBound

func (e *ErrOutOfBounds) WithUpperBound(isInclusive bool) *ErrOutOfBounds

WithUpperBound sets the inclusivity of the upper bound.

Parameters:

  • isInclusive: A boolean indicating whether the upper bound is inclusive.

Returns:

  • *ErrOutOfBound: The error instance for chaining.

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

func NewErrPanic(value any) *ErrPanic

NewErrPanic creates a new ErrPanic error.

Parameters:

  • value: The value that caused the panic.

Returns:

  • *ErrPanic: A pointer to the newly created ErrPanic.

func (*ErrPanic) Error

func (e *ErrPanic) Error() string

Error is a method of the error interface.

Returns:

  • string: The error message of the panic error.

func (*ErrPanic) ErrorIf added in v0.2.43

func (e *ErrPanic) ErrorIf() error

ErrorIf returns the error if the value is not nil.

Returns:

  • error: The error if the value is not nil, nil otherwise.

type ErrUnexpected

type ErrUnexpected struct {
	// Expected is the list of expected values.
	Expected []string

	// Actual is the actual value encountered.
	Actual fmt.Stringer
}

ErrUnexpected represents an error that occurs when an unexpected value is encountered.

func NewErrUnexpected

func NewErrUnexpected(got fmt.Stringer, expected ...string) *ErrUnexpected

NewErrUnexpected creates a new ErrUnexpected error.

Parameters:

  • got: The actual value encountered.
  • expected: The list of expected values.

Returns:

  • *ErrUnexpected: A pointer to the newly created ErrUnexpected.

func (*ErrUnexpected) Error

func (e *ErrUnexpected) Error() string

Error is a method of the error interface.

Returns:

  • string: The error message.

func (*ErrUnexpected) ErrorIf added in v0.2.43

func (e *ErrUnexpected) ErrorIf() error

ErrorIf returns the error if the actual value is not one of the expected values.

Returns:

  • error: The error if the actual value is not one of the expected values, nil otherwise.

type ErrUnexpectedError added in v0.2.34

type ErrUnexpectedError struct {
	// Reason is the reason for the unexpected error.
	Reason error
}

ErrUnexpectedError represents an error that occurs unexpectedly.

func NewErrUnexpectedError added in v0.2.34

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 added in v0.2.34

func (e *ErrUnexpectedError) ChangeReason(reason error)

ChangeReason changes the reason for the unexpected error.

Parameters:

  • reason: The new reason for the unexpected error.

func (*ErrUnexpectedError) Error added in v0.2.34

func (e *ErrUnexpectedError) Error() string

Error is a method of the error interface.

Returns:

  • string: The error message.

func (*ErrUnexpectedError) Unwrap added in v0.2.34

func (e *ErrUnexpectedError) Unwrap() error

Unwrap returns the reason for the unexpected error. It is used for error unwrapping.

Returns:

  • error: The reason for the unexpected error.

type ErrUnexpectedType added in v0.2.43

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 added in v0.2.43

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 added in v0.2.43

func (e *ErrUnexpectedType[T]) Error() string

Error returns the error message: "type <type> is not a valid <kind> type".

Returns:

  • string: The error message.

type ErrVariableError added in v0.2.43

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 added in v0.2.43

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 added in v0.2.43

func (e *ErrVariableError) ChangeReason(reason error)

ChangeReason changes the reason for the variable error.

Parameters:

  • reason: The new reason for the variable error.

func (*ErrVariableError) Error added in v0.2.43

func (e *ErrVariableError) Error() string

Error returns the error message: "variable (<variable>) error" or "variable (<variable>) error: <reason>" if the reason is provided.

Returns:

  • string: The error message.

func (*ErrVariableError) Unwrap added in v0.2.43

func (e *ErrVariableError) Unwrap() error

Unwrap returns the reason for the variable error. It is used for error unwrapping.

Returns:

  • error: The reason for the variable error.

type Errorer added in v0.2.43

type Errorer interface {
	// ErrorIf returns the error if the error itself meets a certain condition.
	//
	// Returns:
	//   - error: The error if the error itself meets a certain condition.
	//     Otherwise, nil.
	ErrorIf() error

	error
}

Errorer is an interface that defines a method to return the error if the error itself meets a certain condition.

type Unwrapper added in v0.2.34

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)

	error
}

Unwrapper is an interface that defines a method to unwrap an error.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL