e

package module
v0.0.0-...-7f1a2ba Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2019 License: BSD-3-Clause Imports: 12 Imported by: 27

README

e

Build Status GoDoc

This package brings a way to stack errors for future reference. There are tools to retrieve this errors and make decisions during run-time.

It's stable but its not for use. I made this package only for use in my others go packages, but I decide to open it for compatibility reasons.

Documentation

Overview

Package e are composed of helper functions to manipulate errors and trace then.

Index

Constants

View Source
const (
	NextIsNill messageType = iota
	Next
	ErrorGo
	ErrorLocal
)

types of error

View Source
const (
	ErrEmptyString      = "empty string"
	ErrInvalidType      = "type is invalid"
	ErrInvalidLength    = "length is invalid"
	ErrInvalidInterface = "invalid interface"
)

Errors

Variables

View Source
var Debug = true

Debug add file name and line number to the error

Functions

func Contains

func Contains(ie interface{}, sub string) bool

Contains checks if the error message contains the sub string.

func Copy

func Copy(ie interface{}) error

Copy creates a copy of an error.

func Equal

func Equal(l, r interface{}) bool

Equal compare if the errors are the same. l must be *Error and r must be *Error, error or string.

func Find

func Find(e, ie interface{}) int

Find an error in the chain. e must be *Error and ie must be *Error, error or string.

func FindStr

func FindStr(ie interface{}, sub string) int

FindStr in a error.

func Forward

func Forward(ie interface{}) error

Forward the error. Only stack the error menssage and the debug data. Free function to use with other types of error besides the *Error. ie must be *Error and r must be *Error, error or string.

func ForwardN

func ForwardN(ie interface{}, n int) error

ForwardN skip n levels from the stack when login the trace.

func Human

func Human(err interface{}) string

Human returns a near human readable form.

func Merge

func Merge(e1, e2 interface{}) error

Merge two errors.

func New

func New(ie interface{}, a ...interface{}) error

New initiates an error from a string, error or *Error. a is the verb in the error string that will be replaced when Error and GoString functions is called. The valids verbs are the same verbs in the fmt package.

func NewN

func NewN(ie interface{}, n int, a ...interface{}) error

NewN like New but with the stack deep to get the file name.

func Phrase

func Phrase(i interface{}) string

Phrase transform an error message in something readable.

func Push

func Push(e1, e2 interface{}) error

Push e2 error on the top of the stack (e1 error). Free function to use with other types of error beside the *Error. e1 must be *Error or error and e2 must be *Error, error or string.

func PushN

func PushN(e1, e2 interface{}, n int) error

PushN like Push but with the stack deep to get the file name.

func String

func String(i interface{}) string

String return the string associated with the error

func Trace

func Trace(ie interface{}) string

Trace the error and return a string. ie must be *Error.

Types

type Error

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

Error expand go error type with debug information and error trace.

func (*Error) Arguments

func (e *Error) Arguments() []interface{}

Arguments return the arguments of one error.

func (*Error) Contains

func (e *Error) Contains(sub string) bool

Contains checks if the error message contains the sub string.

func (*Error) Copy

func (e *Error) Copy() error

Copy create a new copy of e.

func (*Error) Debug

func (e *Error) Debug() bool

Debug return true if the package, file and line are present or false if else.

func (*Error) DecodeMsgpack

func (e *Error) DecodeMsgpack(dec *msgpack.Decoder) error

DecodeMsgpack is a custom msgpack decode function.

func (*Error) EncodeMsgpack

func (e *Error) EncodeMsgpack(enc *msgpack.Encoder) error

EncodeMsgpack custom msgpack encode function

func (*Error) Equal

func (e *Error) Equal(ie interface{}) bool

Equal compare if the errors are the same. ie must be *Error and r must be *Error, error or string.

func (*Error) Error

func (e *Error) Error() string

Error return the packed, file, line number and the error message.

func (*Error) File

func (e *Error) File() string

File returns the file name of the source where occurred the error.

func (*Error) Find

func (e *Error) Find(ie interface{}) int

Find an error in the chain. ie must be *Error, error or string.

func (*Error) FindStr

func (e *Error) FindStr(sub string) int

FindStr find a sub string int the chain of error and return the deep of the error.

func (*Error) Forward

func (e *Error) Forward() *Error

Forward the error. Only stack the error menssage and the debug data.

func (*Error) GoString

func (e *Error) GoString() string

GoString return the same as Error function, more verbose.

func (*Error) GobDecode

func (e *Error) GobDecode(data []byte) error

GobDecode implements custom gob decode.

func (*Error) GobEncode

func (e *Error) GobEncode() ([]byte, error)

GobEncode implements custom gob encode.

func (*Error) Human

func (e *Error) Human() string

Human is a humman readable error.

func (*Error) Line

func (e *Error) Line() int

Line is the line of the error.

func (*Error) Next

func (e *Error) Next() *Error

Next return the next error in the chain

func (*Error) Pkg

func (e *Error) Pkg() string

Pkg return the package where the error occurred.

func (*Error) Push

func (e *Error) Push(ie interface{}) *Error

Push one error on the top of the stack. ie must be *Error, error or string.

func (*Error) String

func (e *Error) String() string

String return only the error message of the last error.

func (*Error) Trace

func (e *Error) Trace() (s string)

Trace the error and return a string.

type GoError

type GoError string

GoError is a simple string thats implement error interface.

func (GoError) Error

func (g GoError) Error() string

Jump to

Keyboard shortcuts

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