Errors

package
v0.2.15 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2024 License: MIT Imports: 6 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

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

type FileLogger struct {

	// The logger to write to the file.
	*log.Logger
	// contains filtered or unexported fields
}

FileLogger is a struct that represents a file logger. It must be closed after use to release the file resources.

func NewFileLogger added in v0.2.11

func NewFileLogger(filePath string) (*FileLogger, error)

NewFileLogger is a function that creates a new FileLogger instance. It creates a new file with the given file path and returns a pointer to the FileLogger instance.

Parameters:

  • filePath: The path of the file to log to.

Returns:

  • *FileLogger: A pointer to the new FileLogger instance.
  • error: An error if the file cannot be created or opened for writing.

The file name is created by appending the ".log.md" extension to the file path.

func (*FileLogger) Close added in v0.2.11

func (fl *FileLogger) Close()

Close is a method of FileLogger that closes the file and releases the resources.

func (*FileLogger) GetFileName added in v0.2.11

func (fl *FileLogger) GetFileName() string

GetFileName is a method of FileLogger that returns the name of the file to log to.

Returns:

  • string: The name of the file to log to.

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