errors

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2019 License: MIT Imports: 6 Imported by: 0

README

go-errors

Adding labeled value to an error

_, err := Foo(a, b) // returned fmt.Errorf("Some error")
if err != nil {
	return errors.WithFields(err).String("a", a).Int("b", b)
}
Some error
	a:value of a\\n	b:42

LICENSE

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

type Error interface {
	Error() string
	WithFields() ErrorWithFields
	Unwrap() error
}

Error is error interface. that has WithFields method.

func New

func New(msg string) Error

New returns new error.

type ErrorWithFields

type ErrorWithFields interface {
	// Error is method for implementation of error.
	Error() string

	// Origin returns original error.
	Origin() error

	// Unwrap returns original error.
	Unwrap() error

	// Format is implementation for fmt.Formatter.
	Format(s fmt.State, verb rune)

	// Set Fields.
	Bool(label string, value bool) ErrorWithFields
	String(label string, value string) ErrorWithFields
	Stringer(label string, value fmt.Stringer) ErrorWithFields
	Bytes(label string, value []byte) ErrorWithFields
	Byte(label string, value byte) ErrorWithFields
	Int(label string, value int) ErrorWithFields
	Int64(label string, value int64) ErrorWithFields
	Int32(label string, value int32) ErrorWithFields
	Int16(label string, value int16) ErrorWithFields
	Int8(label string, value int8) ErrorWithFields
	Uint(label string, value uint) ErrorWithFields
	Uint64(label string, value uint64) ErrorWithFields
	Uint32(label string, value uint32) ErrorWithFields
	Uint16(label string, value uint16) ErrorWithFields
	Uint8(label string, value uint8) ErrorWithFields
	Float64(label string, value float64) ErrorWithFields
	Float32(label string, value float32) ErrorWithFields
	Time(label string, value time.Time, layout string) ErrorWithFields
	UTCTime(label string, value time.Time) ErrorWithFields
	Stack(label string) ErrorWithFields
}

ErrorWithFields annotate

func WithFields

func WithFields(err error) ErrorWithFields

WithFields annotate err with fields.

type WrappedError

type WrappedError interface {
	Error
	Origin() error
}

WrappedError is error and wrapped error. that can handling original error and

func Wrap

func Wrap(err error, msg string) WrappedError

Wrap error and returns error with fields.

func Wrapf

func Wrapf(msg string, err error) WrappedError

Wrapf returns wrapped error.

Jump to

Keyboard shortcuts

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