errors

package
v0.3.33 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2024 License: MIT Imports: 6 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func As

func As[T any](err error) bool

As 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

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

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

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

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

func (e *ErrAfter) ChangeReason(reason error)

ChangeReason implements the Unwrapper interface.

func (*ErrAfter) Error

func (e *ErrAfter) Error() string

Error implements the Unwrapper interface.

Message: "after {after}: {reason}".

However, if the reason is nil, the message is "something went wrong after {after}" instead.

func (*ErrAfter) Unwrap

func (e *ErrAfter) Unwrap() error

Unwrap implements the Unwrapper interface.

type ErrAt

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

	// Name is the name of the index.
	Name string

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

ErrAt represents an error that occurs at a specific index.

func NewErrAt

func NewErrAt(index int, name string, reason error) *ErrAt

NewErrAt creates a new ErrAt error.

Parameters:

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

Returns:

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

func (*ErrAt) ChangeReason

func (e *ErrAt) ChangeReason(reason error)

ChangeReason implements the Unwrapper interface.

func (*ErrAt) Error

func (e *ErrAt) Error() string

Error implements the Unwrapper interface.

Message: "something went wrong at the {index} {name}: {reason}".

However, if the reason is nil, the message is "something went wrong at the {index} {name}" instead.

func (*ErrAt) Unwrap

func (e *ErrAt) Unwrap() error

Unwrap 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

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

func (e *ErrBefore) ChangeReason(reason error)

ChangeReason implements the Unwrapper interface.

func (*ErrBefore) Error

func (e *ErrBefore) Error() string

Error implements the Unwrapper interface.

Message: "before {before}: {reason}".

However, if the reason is nil, the message is "something went wrong before {before}" instead.

func (*ErrBefore) Unwrap

func (e *ErrBefore) Unwrap() error

Unwrap implements the Unwrapper interface.

type ErrEmpty

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

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

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

Error implements the error interface.

Message: "<type> must not be empty"

type ErrGT

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

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

func (e *ErrGT) Error() string

Error implements the error interface.

Message: "value must be greater than <value>"

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

type ErrGTE

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

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

func (e *ErrGTE) Error() string

Error implements the error interface.

Message: "value must be greater than or equal to <value>"

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

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 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.

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

func (e *ErrInvalidCall) ChangeReason(reason error)

ChangeReason implements the Unwrapper interface.

func (*ErrInvalidCall) Error

func (e *ErrInvalidCall) Error() string

Error implements the Unwrapper interface.

Message: "call to {function}({signature}) failed: {reason}".

However, if the reason is nil, the message is "call to {function}({signature}) failed" instead.

func (*ErrInvalidCall) Unwrap

func (e *ErrInvalidCall) Unwrap() error

Unwrap implements the Unwrapper interface.

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.

Parameters:

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

Returns:

  • *ErrInvalidParameter: 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

func (e *ErrInvalidParameter) ChangeReason(reason error)

ChangeReason implements the Unwrapper interface.

func (*ErrInvalidParameter) Error

func (e *ErrInvalidParameter) Error() string

Error implements the Unwrapper interface.

Message: "parameter ({parameter}) is invalid: {reason}".

However, if the reason is nil, the message is "parameter ({parameter}) is invalid" instead.

func (*ErrInvalidParameter) Unwrap

func (e *ErrInvalidParameter) 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 ErrInvalidUsage

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

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

func (e *ErrInvalidUsage) ChangeReason(reason error)

ChangeReason implements the Unwrapper interface.

func (*ErrInvalidUsage) Error

func (e *ErrInvalidUsage) Error() string

Error is a method of the Unwrapper interface.

Message: "{reason}. {usage}".

However, if the reason is nil, the message is "invalid usage. {usage}" instead.

If the usage is empty, no usage is added to the message.

func (*ErrInvalidUsage) Unwrap

func (e *ErrInvalidUsage) Unwrap() error

Unwrap implements the Unwrapper interface.

type ErrInvalidValues

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

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

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

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

Error implements the error interface.

Message: "value must not be <value 0>, <value 1>, <value 2>, ..., or <value n>"

If no values are provided, the message is "value is invalid".

type ErrLT

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

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

func (e *ErrLT) Error() string

Error implements the error interface.

Message: "value must be less than <value>"

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

type ErrLTE

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

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

func (e *ErrLTE) Error() string

Error implements the error interface.

Message: "value must be less than or equal to <value>"

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

type ErrNilValue

type ErrNilValue struct{}

ErrNilValue represents an error when a value is nil.

func NewErrNilValue

func NewErrNilValue() *ErrNilValue

NewErrNilValue creates a new ErrNilValue error.

Returns:

  • *ErrNilValue: The new ErrNilValue error.

func (*ErrNilValue) Error

func (e *ErrNilValue) Error() string

Error implements the error interface.

Message: "pointer must not be nil"

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

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

func (e *ErrOrSol[T]) AddAny(elem any, level int)

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

func (e *ErrOrSol[T]) AddErr(err error, level int)

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

func (e *ErrOrSol[T]) AddSol(sol T, level int)

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]) GetErrors added in v0.3.15

func (e *ErrOrSol[T]) GetErrors() []error

GetErrors returns the list of errors.

Returns:

  • []error: The list of errors.

func (*ErrOrSol[T]) GetSolutions added in v0.3.15

func (e *ErrOrSol[T]) GetSolutions() []T

GetSolutions returns the list of solutions.

Returns:

  • []T: The list of solutions.

func (*ErrOrSol[T]) HasError added in v0.3.15

func (e *ErrOrSol[T]) HasError() bool

HasError checks if errors are not ignored and if the error list is not empty.

Returns:

  • bool: True if errors are not ignored and the error list is not empty, otherwise false.

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. By default, 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 implements the error interface.

Message: "value (value) not in range <lowerBound, upperBound>"

If the lower bound is inclusive, the message uses square brackets. If the upper bound is inclusive, the message uses square brackets. Otherwise, the message uses parentheses.

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 implements the error interface.

Message: "panic: {value}"

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 ErrUnexpected

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

	// Actual is the actual value encountered.
	Actual string
}

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

func NewErrUnexpected

func NewErrUnexpected(got string, 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 implements the error interface.

Message: "expected <value 0>, <value 1>, <value 2>, ..., or <value n>, got <actual> instead"

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

func NewErrWhile(operation string, reason error) *ErrWhile

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

func (e *ErrWhile) ChangeReason(reason error)

ChangeReason implements the Unwrapper interface.

func (*ErrWhile) Error

func (e *ErrWhile) Error() string

Error implements the Unwrapper interface.

Message: "error while {operation}: {reason}"

However, if the reason is nil, the message is "an error occurred while {operation}" instead.

func (*ErrWhile) Unwrap

func (e *ErrWhile) Unwrap() error

Unwrap implements the Unwrapper interface.

type ErrWhileAt

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

	// Element is the element where the index is pointing to.
	Element string

	// Operation is the operation that was being performed.
	Operation string

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

ErrWhileAt represents an error that occurs while performing an operation at a specific index.

func NewErrWhileAt

func NewErrWhileAt(operation string, index int, elem string, reason error) *ErrWhileAt

NewErrWhileAt creates a new ErrWhileAt error.

Parameters:

  • operation: The operation that was being performed.
  • index: The index where the error occurred.
  • elem: The element where the index is pointing to.
  • reason: The reason for the error.

Returns:

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

func (*ErrWhileAt) ChangeReason

func (e *ErrWhileAt) ChangeReason(reason error)

ChangeReason implements the Unwrapper interface.

func (*ErrWhileAt) Error

func (e *ErrWhileAt) Error() string

Error implements the Unwrapper interface.

Message: "an error occurred while {operation} at index {index} {element}: {reason}"

However, if the reason is nil, the message is "an error occurred while {operation} at index {index} {element}" instead.

func (*ErrWhileAt) Unwrap

func (e *ErrWhileAt) Unwrap() error

Unwrap 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)

	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