Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
Errorf is a convenience reference to fmt.Errorf.
New is a convenience reference to errors.New. This avoids having to import this package with an alias.
Functions ¶
This section is empty.
Types ¶
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
Error container type. See ErrorTracer for a description of the interface.
func NewError ¶
NewError creates a new Error instance with the specified error string. Start here when defining new traceable errors.
func (Error) Add ¶
func (e Error) Add(key string, value string) ErrorTracer
Add includes extra metadata with the error.
func (Error) Do ¶
Do the error. Simplistic, concise, and reasonably descriptive: Returns a copy of the traceable error encapsulating the `error` specified.
func (Error) Equal ¶
func (e Error) Equal(err ErrorTracer) bool
Equal checks whether the two errors are equal to each other. Note that this is a relatively simple text and only compares string contents.
func (Error) Error ¶
Error is included to satisfy the error interface.
func (Error) GetMeta ¶
GetMeta returns extra metadata included with the error, if applicable.
func (Error) Is ¶
Is compares whether err is of the same inherited base error as the current error.
type ErrorTracer ¶
type ErrorTracer interface { Add(string, string) ErrorTracer Do(error) Error Equal(ErrorTracer) bool Error() string GetMeta() map[string]string Is(error) bool OriginalError() error }
ErrorTracer defines a "traceable errors" interface. This interface combines the base Error implementation as well as an option for tracing the original error. This package also defines a few helper functions for comparing errors (notably Equal() and Is()). Be aware that this breaks certain expectations regarding how Go's errors should be handled and propogated but provides client code with the option to either a) match or handle the error returned by this package or b) drill down into the underlying cause (i.e. I know an encoding error happened, but what caused it?).
I had written this before discovering pkg/errors, and it's possible this package may be deprecated when (or if) Go2 finally implements something similar.
func Guarantee ¶
func Guarantee(err error) ErrorTracer
Guarantee returns an ErrorTracer regardless of the error's underlying type.
func GuaranteeError ¶
func GuaranteeError(err error, e Error) ErrorTracer
GuaranteeError ensures that the error `err` is of type `e`. If not, it will be wrapped and returned.
func GuaranteeOrNil ¶
func GuaranteeOrNil(err error) ErrorTracer
GuaranteeOrNil guarantees the return of an ErrorTracer or nil, depending on the original type of err.