Errors

package
v0.2.33 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

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.

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 WaitAll

func WaitAll(batch []*GRHandler) []error

WaitAll is a function that waits for all Go routines in the batch to finish and returns a slice of errors that represent the error statuses of the Go routines.

Parameters:

  • batch: A slice of pointers to the GRHandler instances that handle the Go routines.

Returns:

  • []error: A slice of errors that represent the error statuses of the Go routines.

Types

type BatchBuilder

type BatchBuilder struct {
	// contains filtered or unexported fields
}

BatchBuilder is a struct that represents a Go routine batch builder. It is used to build a batch of Go routines and their handlers.

func (*BatchBuilder) Add

func (b *BatchBuilder) Add(identifier string, routine func() error)

Add is a method of BatchBuilder that adds a Go routine to the batch.

Parameters:

  • identifier: The identifier of the Go routine.
  • routine: The Go routine to add to the batch.

func (*BatchBuilder) Build

func (b *BatchBuilder) Build() []*GRHandler

Build is a method of BatchBuilder that builds the batch of Go routines and their handlers.

Returns:

  • []*GRHandler: A slice of pointers to the GRHandler instances that handle the Go routines.

All Go routines are automatically run when this method is called. Finally, the batch is cleared after the Go routines are built.

func (*BatchBuilder) Clear

func (b *BatchBuilder) Clear()

Clear is a method of BatchBuilder that clears the batch of Go routines.

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

type ErrEmptySlice struct{}

ErrEmptySlice represents an error when a slice is empty.

func NewErrEmptySlice added in v0.2.33

func NewErrEmptySlice() *ErrEmptySlice

NewErrEmptySlice creates a new ErrEmptySlice error.

Returns:

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

func (*ErrEmptySlice) Error added in v0.2.33

func (e *ErrEmptySlice) Error() string

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

Returns:

  • string: The error message.

type ErrEmptyString added in v0.2.32

type ErrEmptyString struct{}

ErrEmptyString represents an error when a string is empty.

func NewErrEmptyString added in v0.2.32

func NewErrEmptyString() *ErrEmptyString

NewErrEmptyString creates a new ErrEmptyString error.

Returns:

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

func (*ErrEmptyString) Error added in v0.2.32

func (e *ErrEmptyString) Error() string

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

Returns:

  • string: The error message.

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.

Parameters:

  • value: The value that caused the error.

Returns:

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

func (*ErrGT) Error added in v0.2.32

func (e *ErrGT) Error() string

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

Returns:

  • string: The error message.

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.

Parameters:

  • value: The value that caused the error.

Returns:

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

func (*ErrGTE) Error added in v0.2.32

func (e *ErrGTE) Error() string

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

Returns:

  • string: The error message.

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

func (e *ErrIgnorable) Error() string

Error is a method of the error interface.

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) 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 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, errors.New("value is nil")).

Parameters:

  • parameter: The name of the parameter.

Returns:

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

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) 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 ErrInvalidValue added in v0.2.32

type ErrInvalidValue struct {
	// Values is the list of invalid values.
	Values []int
}

ErrInvalidValue represents an error when a value is invalid.

func NewErrInvalidValue added in v0.2.32

func NewErrInvalidValue(values ...int) *ErrInvalidValue

NewErrInvalidValue creates a new ErrInvalidValue error.

Parameters:

  • values: The list of invalid values.

Returns:

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

func (*ErrInvalidValue) Error added in v0.2.32

func (e *ErrInvalidValue) Error() string

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

Returns:

  • string: The error message.

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.

Parameters:

  • value: The value that caused the error.

Returns:

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

func (*ErrLT) Error added in v0.2.32

func (e *ErrLT) Error() string

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

Returns:

  • string: The error message.

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.

Parameters:

  • value: The value that caused the error.

Returns:

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

func (*ErrLTE) Error added in v0.2.32

func (e *ErrLTE) Error() string

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

Returns:

  • string: The error message.

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

func (e *ErrNoError) Unwrap() error

Unwrap is a method of the errors interface.

Returns:

  • error: The reason for the no error error.

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

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.

type GRHandler

type GRHandler struct {
	// contains filtered or unexported fields
}

GRHandler is a struct that represents a Go routine handler. It is used to handle the result of a Go routine.

func GoRun

func GoRun(id string, routine func() error) *GRHandler

GoRun is a function that runs a Go routine and returns a GRHandler to handle the result of the Go routine.

Parameters:

  • id: The identifier of the Go routine.
  • routine: The Go routine to run.

Returns:

  • *GRHandler: A pointer to the GRHandler that handles the result of the Go routine.

The Go routine is automatically run when this function is called.

func (*GRHandler) Identifier

func (h *GRHandler) Identifier() string

Identifier is a method of GRHandler that returns the identifier of the Go routine.

Returns:

  • string: The identifier of the Go routine.

func (*GRHandler) Wait

func (h *GRHandler) Wait() error

Wait is a method of GRHandler that waits for the Go routine to finish and returns the error status of the Go routine.

Returns:

  • error: The error status of the Go routine.

Jump to

Keyboard shortcuts

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