internal

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatYAML

func FormatYAML(err Error) string

FormatYAML returns a YAML-formatted string representation of err.

Types

type Error

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

Error is the base type for module-specific errors.

Every Error contains a single base error, called the "cause".

One or more errors may be wrapped by an Error to express a chain or composition of errors, especially when multiple error conditions apply to a single operation.

When initialized using a Make* constructor (or Wrap), Error records the context in which it was created including the callsite, stacktrace, and datetime.

Many of the module's exported functions return an Error that wraps standard errors from the Go standard library.

Error supports the errors.Is interface so that wrapped external errors can be compared directly.

Error Abstractions

The following constructors return common errors that should be used as containers for more specific errors, or when the specific cause of an error is not immediately known:

  • MakeInvalidArgumentError
  • MakeInvalidOperationError
var ErrInvalidError Error

ErrInvalidError is returned when the Error object itself is not valid.

func MakeError

func MakeError(cause error) Error

MakeError returns a new Error with the given cause. The returned error contains the current datetime and a stacktrace relative to the time and location MakeError was called.

func MakeFormatError

func MakeFormatError(cause error, format Format) Error

MakeFormatError returns a new Error with the given cause and formatter. The returned error contains the current datetime and a stacktrace relative to the time and location MakeFormatError was called.

func MakeInvalidArgumentError

func MakeInvalidArgumentError(err ...error) Error

MakeInvalidArgumentError returns a new Error with the given cause.

func MakeInvalidOperationError

func MakeInvalidOperationError(err ...error) Error

MakeInvalidOperationError returns a new Error with the given cause.

func UnformatYAML

func UnformatYAML(err string) Error

func (Error) Cause

func (e Error) Cause() error

Cause returns the base error that caused e.

func (Error) Error

func (e Error) Error() string

Error returns a string representation of e.

func (Error) Is

func (e Error) Is(err error) bool

Is reports whether the given error err is equivalent to e.

The given error err is equivalent to e if either of the following are true:

  1. e.Cause() is equal to err; or
  2. err is an Error, and e.Cause() is equal to err.Cause().

In other words, Is compares the base errors — Error.Cause — of e and err, and it does not consider the wrapped error chains or the datetime of either.

It must only compare the base errors (i.e., a "shallow" comparison) so that errors.Is can recursively shallow-compare all wrapped errors in a single pass.

The Go doc comment on errors.Is states:

An Is method should only shallowly compare err and the target and not
call Unwrap on either.

func (Error) Unwrap

func (e Error) Unwrap() []error

Unwrap returns the slice of all non-nil errors wrapped by e. If e contains no wrapped errors, Unwrap returns nil.

In particular, Unwrap never returns an empty slice.

func (Error) When

func (e Error) When() time.Time

When returns the datetime when e was created.

func (Error) Wrap

func (e Error) Wrap(err ...error) Error

Wrap replaces all wrapped errors in e with all non-nil errors in err. If err contains no non-nil errors, Wrap returns e with no errors wrapped.

type Format

type Format func(Error) string

Format functions return a formatted string representation of a given Error.

Jump to

Keyboard shortcuts

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