Feat (new package): xerrors, easily handle stacks of errors #35
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
xerrors
Package xerrors provides a stack of multiple errors that can be pushed to,
popped from, and concatenated.
type ErrorStack
type Errors
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
NewErrors returns a new [Errors] stack.
func (*Errors) As
func (*Errors) Clear
Clear clears the error stack.
func (*Errors) Concat
Concat concatenates all errors in the stack into a single error. It does not
clear the original stack.
func (*Errors) Copy
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
Error implements the error interface. Internally it uses [Errors.Concat].
func (*Errors) Errors
Errors returns a slice containing a copy of all errors in the stack. It does not
clear the original stack.
func (*Errors) Is
func (*Errors) Len
Len returns the number of errors in the stack.
func (*Errors) Next
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
Pop pops one error from the stack, removing it from the stack and returning it.
func (*Errors) PopAll
func (*Errors) PopAllImmutable
PopAllImmutable returns an immutable copy of the error stack, and clears the
original stack, leaving it empty.
func (*Errors) Push
Push adds an error to the stack. It is safe for concurrent use.
func (*Errors) Seek
Seek implements an [io.Seeker] for the purposes of controlling
[errstack.Errors.Next] output.
type ErrorsImmutable
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 (*ErrorsImmutable) Error
func (*ErrorsImmutable) Errors
func (*ErrorsImmutable) Is
func (*ErrorsImmutable) Len
func (*ErrorsImmutable) Next
func (*ErrorsImmutable) Seek