Errors

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2024 License: MIT Imports: 8 Imported by: 4

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