Skip to content

Commit 7664a77

Browse files
committed
Do not use errgo nor pkg/errors for root errors
Related to #582
1 parent 6cc4a9b commit 7664a77

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

errors/errctx.go

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package errors
22

33
import (
44
"context"
5+
stderrors "errors"
6+
"fmt"
57

68
"github.com/pkg/errors"
79
"gopkg.in/errgo.v1"
@@ -25,30 +27,41 @@ func (err ErrCtx) Unwrap() error {
2527
return err.err
2628
}
2729

28-
func New(ctx context.Context, message string) error {
29-
return ErrCtx{ctx: ctx, err: errgo.New(message)}
30+
// New wraps errors.New from the standard library
31+
//
32+
// These errors are usually created outside any function code at the top of
33+
// files, so no context is needed nor wrapping is needed.
34+
func New(message string) error {
35+
return stderrors.New(message)
36+
}
37+
38+
func NewWithCtx(ctx context.Context, message string) error {
39+
return ErrCtx{ctx: ctx, err: errors.New(message)}
3040
}
3141

3242
func Newf(ctx context.Context, format string, args ...interface{}) error {
33-
return ErrCtx{ctx: ctx, err: errgo.Newf(format, args...)}
43+
return ErrCtx{ctx: ctx, err: fmt.Errorf(format, args...)}
44+
}
45+
46+
func Errorf(ctx context.Context, format string, args ...interface{}) error {
47+
return Newf(ctx, format, args...)
3448
}
3549

50+
// Notef is wrapping an error with the underneath errgo library
3651
func Notef(ctx context.Context, err error, format string, args ...interface{}) error {
3752
return ErrCtx{ctx: ctx, err: errgo.Notef(err, format, args...)}
3853
}
3954

55+
// Wrap is wrapping an error with the underneath errgo library
4056
func Wrap(ctx context.Context, err error, message string) error {
4157
return ErrCtx{ctx: ctx, err: errors.Wrap(err, message)}
4258
}
4359

60+
// Wrapf is wrapping an error with the underneath errgo library
4461
func Wrapf(ctx context.Context, err error, format string, args ...interface{}) error {
4562
return ErrCtx{ctx: ctx, err: errors.Wrapf(err, format, args...)}
4663
}
4764

48-
func Errorf(ctx context.Context, format string, args ...interface{}) error {
49-
return ErrCtx{ctx: ctx, err: errors.Errorf(format, args...)}
50-
}
51-
5265
// RootCtxOrFallback unwrap all wrapped errors from err to get the deepest context
5366
// from ErrCtx errors. If there is no wrapped ErrCtx RootCtxOrFallback returns ctx from parameter.
5467
func RootCtxOrFallback(ctx context.Context, err error) context.Context {

0 commit comments

Comments
 (0)