Permalink
Browse files

issue #45: improve errors package

  • Loading branch information...
kamilsk committed May 1, 2018
1 parent 5df4b1b commit 7252a307c6bd762414965dc507060fda1690db26
Showing with 7 additions and 0 deletions.
  1. +7 −0 errors/wrapper.go
@@ -8,10 +8,12 @@ import (
"github.com/pkg/errors"
)

// Errorf is a proxy for `github.com/pkg/errors.Errorf`.
func Errorf(format string, args ...interface{}) error {
return errors.Errorf(format, args...)
}

// Recover recovers execution flow and sets error to the passed error pointer.
func Recover(err *error) {
if r := recover(); r != nil {
if e, is := r.(error); is {
@@ -22,10 +24,13 @@ func Recover(err *error) {
}
}

// Simple returns text-based error without stack trace.
func Simple(message string) error {
return core.New(message)
}

// StackTrace tries to extract stack trace from the error
// or returns nil if it can't.
func StackTrace(err error) errors.StackTrace {
type stackTracer interface {
StackTrace() errors.StackTrace
@@ -37,10 +42,12 @@ func StackTrace(err error) errors.StackTrace {
return nil
}

// WithMessage is a proxy for `github.com/pkg/errors.WithMessage`.
func WithMessage(err error, message string) error {
return errors.WithMessage(err, message)
}

// Wrapf is a proxy for `github.com/pkg/errors.Wrapf`.
func Wrapf(err error, format string, args ...interface{}) error {
return errors.Wrapf(err, format, args...)
}

0 comments on commit 7252a30

Please sign in to comment.