xerrors

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2024 License: Unlicense Imports: 4 Imported by: 0

Documentation

Overview

Package xerrors provides a stack of multiple errors that can be pushed to, popped from, and concatenated.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrorStack

type ErrorStack interface {
	Len() int
	Is(error) bool
	As(interface{}) bool
	Errors() []error
	Next() error
	io.Seeker
	error
}

type Errors

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

Errors is a stack of multiple errors that can be pushed to, popped from, or concatenated. It is safe for concurrent use, and can return an immutable copy of itself as an [errstack.ErrorsImmutable].

func NewErrors

func NewErrors() *Errors

NewErrors returns a new Errors stack.

func (*Errors) As

func (e *Errors) As(target interface{}) bool

func (*Errors) Clear

func (e *Errors) Clear()

Clear clears the error stack.

func (*Errors) Concat

func (e *Errors) Concat() error

Concat concatenates all errors in the stack into a single error. It does not clear the original stack.

func (*Errors) Copy

func (e *Errors) Copy() *ErrorsImmutable

Copy returns an immutable copy of the error stack. It does not clear the original stack. Copy is safe to call concurrently.

func (*Errors) Error

func (e *Errors) Error() string

Error implements the error interface. Internally it uses Errors.Concat.

func (*Errors) Errors

func (e *Errors) Errors() []error

Errors returns a slice containing a copy of all errors in the stack. It does not clear the original stack.

func (*Errors) Is

func (e *Errors) Is(sought error) bool

func (*Errors) Len

func (e *Errors) Len() int

Len returns the number of errors in the stack.

func (*Errors) Next

func (e *Errors) Next() error

Next returns the next error in the stack, incrementing the internal index. If we've reached the end of the stack, it returns nil.

Use [errstack.Errors.Seek] to rewind the internal index if needed.

func (*Errors) Pop

func (e *Errors) Pop() error

Pop pops one error from the stack, removing it from the stack and returning it.

func (*Errors) PopAll

func (e *Errors) PopAll() []error

func (*Errors) PopAllImmutable

func (e *Errors) PopAllImmutable() *ErrorsImmutable

PopAllImmutable returns an immutable copy of the error stack, and clears the original stack, leaving it empty.

func (*Errors) Push

func (e *Errors) Push(err error)

Push adds an error to the stack. It is safe for concurrent use.

func (*Errors) Seek

func (e *Errors) Seek(offset int64, whence int) (int64, error)

Seek implements an io.Seeker for the purposes of controlling [errstack.Errors.Next] output.

type ErrorsImmutable

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

ErrorsImmutable is a stack of multiple errors popped from [errstack.Errors]. Internally it contains a private [errstack.Errors] with the immutable flag set to true.

It's public methods are a partial subset of [errstack.Errors] methods operating as pass-throughs. Consequently, more information on the contained methods can be found in the [errstack.Errors] documentation.

func (*ErrorsImmutable) As

func (e *ErrorsImmutable) As(i interface{}) bool

func (*ErrorsImmutable) Error

func (e *ErrorsImmutable) Error() string

func (*ErrorsImmutable) Errors

func (e *ErrorsImmutable) Errors() []error

func (*ErrorsImmutable) Is

func (e *ErrorsImmutable) Is(err error) bool

func (*ErrorsImmutable) Len

func (e *ErrorsImmutable) Len() int

func (*ErrorsImmutable) Next

func (e *ErrorsImmutable) Next() error

func (*ErrorsImmutable) Seek

func (e *ErrorsImmutable) Seek(offset int64, whence int) (int64, error)

Jump to

Keyboard shortcuts

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