Skip to content
This repository has been archived by the owner on May 11, 2022. It is now read-only.

Commit

Permalink
issue #45: improve errors package
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilsk committed May 1, 2018
1 parent 5df4b1b commit 7252a30
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions errors/wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand All @@ -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.