definitions

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: May 21, 2025 License: Apache-2.0 Imports: 1 Imported by: 8

Documentation

Overview

Package definitions provides useful error types such as 'MultiError'.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MultiError

type MultiError struct {

	// OutputCap is the maximum number of bytes to be used for error messages. If 0, we don't cap.
	OutputCap int

	// Prefix will be printed before the errors in this MultiError.
	Prefix string
	// Separator will separate the errors in this MultiError.
	// If omitted, defaults to "; ".
	Separator string
	// contains filtered or unexported fields
}

MultiError aggregates multiple errors into a single error value.

The zero value of MultiError is ready for use.

NOTE: MultiError is not safe for concurrent use and needs to be wrapped in a lock to be shared safely between threads.

func (*MultiError) Add

func (m *MultiError) Add(err error)

Add adds a new error to this MultiError.

func (*MultiError) ErrOrNil

func (m *MultiError) ErrOrNil() error

ErrOrNil returns this MultiError if it has at least one error, or nil otherwise. The intended use case is the following:

return foo, errs.ErrOrNil()

instead of:

if len(errs.Errors()) > 0 {
	return nil, errs
}

return foo, nil

func (*MultiError) Error

func (m *MultiError) Error() string

func (*MultiError) Errors

func (m *MultiError) Errors() []error

Errors returns the full list of errors accumulated by this MultiError, or nil if there are none.

NOTE: Callers must not modify the returned slice.

Jump to

Keyboard shortcuts

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