errors

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: May 4, 2018 License: MIT Imports: 4 Imported by: 50

README

Errors

A error package supports wrapping and multi error

Documentation

Overview

Package errors provides multi error, error wrapping. It defines error category code for machine post processing

Index

Examples

Constants

View Source
const (
	// MultiErrSep is the separator used when returning a slice of errors as single line message
	MultiErrSep = "; "
	// ErrCauseSep is the separator used when returning a error with causal chain as single line message
	ErrCauseSep = ": "
)

Variables

This section is empty.

Functions

func Errorf

func Errorf(format string, args ...interface{}) error

func IsRuntimeError

func IsRuntimeError(err error) bool

func New

func New(msg string) error

func Wrap

func Wrap(err error, msg string) error
Example

TODO: we should write test in errors_test package, especially for examples ...

err := Wrap(os.ErrNotExist, "oops")
fmt.Println(err)
Output:

oops: file does not exist

func Wrapf

func Wrapf(err error, format string, args ...interface{}) error

Types

type FreshError

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

func (*FreshError) Error

func (fresh *FreshError) Error() string

func (*FreshError) ErrorStack

func (fresh *FreshError) ErrorStack() *Stack

func (*FreshError) Format

func (fresh *FreshError) Format(s fmt.State, verb rune)

type MultiErr

type MultiErr interface {
	error
	fmt.Formatter
	// Append returns true if the appended error is not nil, inspired by https://github.com/uber-go/multierr/issues/21
	Append(error) bool
	Errors() []error
	// Error returns itself or nil if there are no errors, inspired by https://github.com/hashicorp/go-multierror
	ErrorOrNil() error
	// HasError is ErrorOrNil != nil
	HasError() bool
}
Example
err := NewMultiErr()
err.Append(os.ErrPermission)
err.Append(os.ErrNotExist)
fmt.Println(err.Errors())
Output:

[permission denied file does not exist]

func NewMultiErr

func NewMultiErr() MultiErr

func NewMultiErrSafe

func NewMultiErrSafe() MultiErr

type Stack

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

func (*Stack) Frames

func (s *Stack) Frames() []runtime.Frame

type TracedError

type TracedError interface {
	fmt.Formatter
	ErrorStack() *Stack
}

type WrappedError

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

func (*WrappedError) Error

func (wrapped *WrappedError) Error() string

func (*WrappedError) ErrorStack

func (wrapped *WrappedError) ErrorStack() *Stack

func (*WrappedError) Format

func (wrapped *WrappedError) Format(s fmt.State, verb rune)

Jump to

Keyboard shortcuts

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