errored: github.com/contiv/errored Index | Files

package errored

import "github.com/contiv/errored"

Package errored implements specialized errors for golang that come with:

* Debug and Trace modes
* Debug emits the location the error was created, Trace emits the whole stack.
* Error combination
* Make two errors into one; carries the trace information for both errors with it!

Use it just like `fmt`:

package main

import "github.com/contiv/errored"

func main() {
	err := errored.Errorf("a message")
	err.SetDebug(true)
	err.Error() // => "a message [ <file> <line> <line number> ]
	err2 := errored.Errorf("another message")
	combined := err.Combine(err2)
	combined.SetTrace(true)
	combined.Error() // => "a message: another message" + two stack traces
	combined.Contains(err2) // => true
}

Index

Package Files

errored.go

Variables

var (
    // AlwaysTrace will, if set globally, enable tracing on all errors.
    AlwaysTrace bool
    // AlwaysDebug will, if set globally, enable debug messages on all errors.
    AlwaysDebug bool
)

type Error Uses

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

Error is our custom error with description, file, and line.

func Errorf Uses

func Errorf(f string, args ...interface{}) *Error

Errorf returns an *Error based on the format specification provided.

func New Uses

func New(desc string) *Error

New constructs a new error with the provided text.

func (*Error) Combine Uses

func (e *Error) Combine(e2 error) *Error

Combine combines two errors into a single one.

func (*Error) Contains Uses

func (e *Error) Contains(err error) bool

Contains is a predicate that returns if any errors in the combined error collection that are of this error.

func (*Error) ContainsFunc Uses

func (e *Error) ContainsFunc(f func(error) bool) bool

ContainsFunc is like Contains but instead iterates over the errors and executes a predicate function instead.

func (*Error) Error Uses

func (e *Error) Error() string

Error() allows *core.Error to present the `error` interface.

func (*Error) SetDebug Uses

func (e *Error) SetDebug(debug bool)

SetDebug enables the per-error caller information of errored's Error struct.

func (*Error) SetTrace Uses

func (e *Error) SetTrace(trace bool)

SetTrace enables the tracing capabilities of errored's Error struct.

Please note that SetTrace automatically sets debug mode too if enabled. See SetDebug.

func (*Error) String Uses

func (e *Error) String() string

Package errored imports 4 packages (graph) and is imported by 27 packages. Updated 2016-07-17. Refresh now. Tools for package owners.