Errors

package
v0.2.8 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrInvalidParameter

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

ErrInvalidParameter represents an error when a parameter is invalid. It holds the parameter name and the reason for its invalidity.

func NewErrInvalidParameter

func NewErrInvalidParameter(parameter string) *ErrInvalidParameter

NewErrInvalidParameter creates a new ErrInvalidParameter error. The parameter name is passed as an argument. The reason for the invalidity is set to "parameter is invalid" by default.

func (*ErrInvalidParameter) Error

func (e *ErrInvalidParameter) Error() string

Error generates the error message for the ErrInvalidParameter error. The message includes the parameter name and the reason for its invalidity.

func (*ErrInvalidParameter) Unwrap

func (e *ErrInvalidParameter) Unwrap() error

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

func (*ErrInvalidParameter) WithReason

func (e *ErrInvalidParameter) WithReason(reason error) *ErrInvalidParameter

WithReason sets the reason for the invalidity of the parameter. If the reason is nil, it does not change the existing reason. It returns the ErrInvalidParameter 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. It holds the lower and upper bounds of the range, the value that caused the error, and flags indicating whether the bounds are inclusive.

func NewErrOutOfBound

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

NewErrOutOfBound creates a new ErrOutOfBound error. The lower bound is exclusive and the upper bound is inclusive by default. The bounds and the value that caused the error are passed as arguments.

func (*ErrOutOfBound) Error

func (e *ErrOutOfBound) Error() string

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

func (*ErrOutOfBound) WithLowerBound

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

WithLowerBound sets the inclusivity of the lower bound. If isInclusive is true, the lower bound is inclusive. It returns the ErrOutOfBound instance for chaining.

func (*ErrOutOfBound) WithUpperBound

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

WithUpperBound sets the inclusivity of the upper bound. If isInclusive is true, the upper bound is inclusive. It returns the ErrOutOfBound instance for chaining.

Jump to

Keyboard shortcuts

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