Errors

package
v0.2.25 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: 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 IsNoError added in v0.2.12

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

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

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

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

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

func (b *BatchBuilder) Clear()

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

type ErrCallFailed added in v0.2.9

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

ErrCallFailed represents an error that occurs when a function call fails.

func NewErrCallFailed added in v0.2.9

func NewErrCallFailed(functionName string, function any) *ErrCallFailed

NewCallFailed creates a new ErrCallFailed. 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:

  • error: A pointer to the new ErrCallFailed.

func (*ErrCallFailed) Error added in v0.2.9

func (e *ErrCallFailed) Error() string

Error generates a string representation of an ErrCallFailed, including the function name, signature, and the reason for the failure.

Returns:

  • string: The error message.

func (*ErrCallFailed) Unwrap added in v0.2.9

func (e *ErrCallFailed) Unwrap() error

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

Returns:

  • error: The reason for the failure.

func (*ErrCallFailed) Wrap added in v0.2.22

func (e *ErrCallFailed) Wrap(reason error) *ErrCallFailed

Wrap sets the reason for the failure. If the reason is not provided (nil), the reason is set to "an error occurred while calling the function" by default.

Parameters:

  • reason: The reason for the failure.

Returns:

  • *ErrCallFailed: The error instance for chaining.

type ErrInvalidParameter

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

ErrInvalidParameter represents an error when a parameter is invalid.

func NewErrInvalidParameter

func NewErrInvalidParameter(parameter string) *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 added in v0.2.24

func NewErrNilParameter(parameter string) *ErrInvalidParameter

ErrNilParameter represents an error when a parameter is nil. This is a shorthand for NewErrInvalidParameter(parameter).Wrap(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 generates the error message for the ErrInvalidParameter error, including the parameter name and the reason for its invalidity.

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.

func (*ErrInvalidParameter) Wrap added in v0.2.13

Wrap sets the reason for the invalidity of the parameter. If the reason is not provided (nil), the reason is set to "parameter is invalid" by default.

type ErrNoError added in v0.2.12

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

ErrNoError represents an error when no error occurs.

func NewErrNoError added in v0.2.12

func NewErrNoError(reason error) *ErrNoError

NewErrNoError creates a new ErrNoError error.

Parameters:

  • reason: The reason for the no error error.

Returns:

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

func (*ErrNoError) Error added in v0.2.12

func (e *ErrNoError) Error() string

Error generates the error message for the ErrNoError error, that is, the reason for the no error error.

Returns:

  • string: The error message.

func (*ErrNoError) Unwrap added in v0.2.12

func (e *ErrNoError) Unwrap() error

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

Returns:

  • error: The reason for the no error error.

func (*ErrNoError) Wrap added in v0.2.13

func (e *ErrNoError) Wrap(reason error) *ErrNoError

Wrap sets the reason for the no error error.

Parameters:

  • reason: The reason for the no error error.

Returns:

  • *ErrNoError: The error instance for chaining.

type ErrOutOfBound

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

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

func NewErrOutOfBound

func NewErrOutOfBound(value int, lowerBound, upperBound int) *ErrOutOfBound

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

  • error: A pointer to the newly created ErrOutOfBound.

func (*ErrOutOfBound) Error

func (e *ErrOutOfBound) Error() string

Error generates the error message for the ErrOutOfBound error, including the value, the range, and whether the bounds are inclusive. The message includes the range, and whether the bounds are inclusive.

Returns:

  • string: The error message.

func (*ErrOutOfBound) WithLowerBound

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

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 (*ErrOutOfBound) WithUpperBound

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

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

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

ErrPanic represents an error when a panic occurs.

func NewErrPanic added in v0.2.11

func NewErrPanic(value any) *ErrPanic

NewErrPanic creates a new ErrPanic error.

Parameters:

  • value: The value that caused the panic.

Returns:

  • error: A pointer to the newly created ErrPanic.

func (*ErrPanic) Error added in v0.2.11

func (e *ErrPanic) Error() string

Error generates the error message for the ErrPanic error, including the value that caused the panic.

Returns:

  • string: The error message.

type ErrUnexpected added in v0.2.24

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

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

func NewErrUnexpected added in v0.2.24

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

func (e *ErrUnexpected) Error() string

Error generates a string representation of an ErrUnexpected, including the expected values and the actual value encountered.

type GRHandler added in v0.2.11

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

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

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

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