errored

package module
v0.0.0-...-b397b14 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2016 License: Apache-2.0 Imports: 4 Imported by: 63

README

ReportCard Build GoDoc

Errored: flexible error messages for golang

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
}

Authors:

  • Madhav Puri
  • Erik Hollensbe

Sponsorship

Project Contiv is sponsored by Cisco Systems, Inc.

Documentation

Overview

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

Constants

This section is empty.

Variables

View Source
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
)

Functions

This section is empty.

Types

type Error

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

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

func Errorf

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

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

func New

func New(desc string) *Error

New constructs a new error with the provided text.

func (*Error) Combine

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

Combine combines two errors into a single one.

func (*Error) Contains

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

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

func (e *Error) Error() string

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

func (*Error) SetDebug

func (e *Error) SetDebug(debug bool)

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

func (*Error) SetTrace

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

func (e *Error) String() string

Jump to

Keyboard shortcuts

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