erg

package
v0.5.11 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2022 License: MIT Imports: 5 Imported by: 2

Documentation

Overview

Package erg allows grouping errors into an error group.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Any

func Any(groupErr error) bool

Any checks if there are any errors in the group. If groupErr is not Groupable, false is returned.

func Append

func Append(groupErr error, errs ...error) error

Append to an error group. If groupError is not Groupable, nothing happens.

func GetErrors

func GetErrors(groupErr error) []error

GetErrors from an error group. If groupErr is not Groupable, nil is returned.

func New

func New(kind erk.Kind, message string, errs ...error) error

New creates an error group with a kind and message.

func NewAs

func NewAs(header error, errs ...error) error

NewAs creates an error group given a header error.

Best combined with erk.New().

Types

type ExportedGroup

type ExportedGroup struct {
	*erk.ExportedError
	Errors []erk.ExportedErkable `json:"errors"`
}

ExportedGroup that can be used outside the erg package. A common use case is marshalling the error to JSON.

ExportedGroup satisfies the erk.ExportedErkable and the erg.ExportedGroupable interface.

func (*ExportedGroup) GroupErrors

func (g *ExportedGroup) GroupErrors() []erk.ExportedErkable

GroupErrors satisfies the ExportedGroupable interface.

type ExportedGroupable

type ExportedGroupable interface {
	GroupErrors() []erk.ExportedErkable
}

ExportedGroupable is an exported readonly version of Groupable.

type Group

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

Group of errors.

func (*Group) Append

func (g *Group) Append(errs ...error) error

Append errors to the group. Skips nil errors.

func (*Group) Error

func (g *Group) Error() string

Error implements the error interface. It prints the header and list of errors.

func (*Group) Errors

func (g *Group) Errors() []error

Errors returns a copy of all errors of the group.

func (*Group) Export

func (g *Group) Export() erk.ExportedErkable

Export the group to an ExportedGroup.

func (*Group) ExportRawMessage added in v0.5.6

func (g *Group) ExportRawMessage() string

ExportRawMessage without executing the template.

func (*Group) Header added in v0.3.5

func (g *Group) Header() error

Header of the error group.

func (*Group) IndentError added in v0.4.1

func (g *Group) IndentError(indentLevel string) string

IndentError converts the error group to a string given the provided indentation.

func (*Group) Is added in v0.3.1

func (g *Group) Is(target error) bool

Is implements the Go 1.13+ Is interface for use with errors.Is.

Is first checks for a match against the group header, and then checks for a match against each error in the group.

func (*Group) Kind

func (g *Group) Kind() erk.Kind

Kind returns the error Kind of the group header.

func (*Group) MarshalJSON added in v0.5.3

func (g *Group) MarshalJSON() ([]byte, error)

MarshalJSON by exporting the error group and then marshalling.

func (*Group) Params

func (g *Group) Params() erk.Params

Params gets params from the group header.

func (*Group) WithParams

func (g *Group) WithParams(params erk.Params) error

WithParams adds params to the group header.

type Groupable

type Groupable interface {
	Header() error
	Append(errs ...error) error
	Errors() []error
}

Groupable errors can append to and fetch the error group.

Jump to

Keyboard shortcuts

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