Skip to content

Commit d310f9d

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

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

errors/errctx.go

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,30 +25,41 @@ func (err ErrCtx) Unwrap() error {
2525
return err.err
2626
}
2727

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

3240
func Newf(ctx context.Context, format string, args ...interface{}) error {
33-
return ErrCtx{ctx: ctx, err: errgo.Newf(format, args...)}
41+
return ErrCtx{ctx: ctx, err: errors.Errorf(format, args...)}
3442
}
3543

44+
func Errorf(ctx context.Context, format string, args ...interface{}) error {
45+
return ErrCtx{ctx: ctx, err: errors.Errorf(format, args...)}
46+
}
47+
48+
// Notef is wrapping an error with the underneath errgo library
3649
func Notef(ctx context.Context, err error, format string, args ...interface{}) error {
3750
return ErrCtx{ctx: ctx, err: errgo.Notef(err, format, args...)}
3851
}
3952

53+
// Wrap is wrapping an error with the underneath errgo library
4054
func Wrap(ctx context.Context, err error, message string) error {
4155
return ErrCtx{ctx: ctx, err: errors.Wrap(err, message)}
4256
}
4357

58+
// Wrapf is wrapping an error with the underneath errgo library
4459
func Wrapf(ctx context.Context, err error, format string, args ...interface{}) error {
4560
return ErrCtx{ctx: ctx, err: errors.Wrapf(err, format, args...)}
4661
}
4762

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

0 commit comments

Comments
 (0)