debug.go 625 Bytes
Newer Older
1
// package errors provides ways to augment errors with additional
Brian Tiger Chow's avatar
Brian Tiger Chow committed
2
// information to allow for easier debugging.
3
package errors
Brian Tiger Chow's avatar
Brian Tiger Chow committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30

import (
	"errors"
	"fmt"

	"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/facebookgo/stackerr"
	"github.com/jbenet/go-ipfs/util"
)

func Errorf(format string, a ...interface{}) error {
	return Wrap(fmt.Errorf(format, a...))
}

// New returns an error that contains a stack trace (in debug mode)
func New(s string) error {
	if util.Debug {
		return stackerr.New(s)
	}
	return errors.New(s)
}

func Wrap(err error) error {
	if util.Debug {
		return stackerr.Wrap(err)
	}
	return err
}