@@ -2,6 +2,8 @@ package errors
2
2
3
3
import (
4
4
"context"
5
+ stderrors "errors"
6
+ "fmt"
5
7
6
8
"github.com/pkg/errors"
7
9
"gopkg.in/errgo.v1"
@@ -25,30 +27,41 @@ func (err ErrCtx) Unwrap() error {
25
27
return err .err
26
28
}
27
29
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 )}
30
40
}
31
41
32
42
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 ... )
34
48
}
35
49
50
+ // Notef is wrapping an error with the underneath errgo library
36
51
func Notef (ctx context.Context , err error , format string , args ... interface {}) error {
37
52
return ErrCtx {ctx : ctx , err : errgo .Notef (err , format , args ... )}
38
53
}
39
54
55
+ // Wrap is wrapping an error with the underneath errgo library
40
56
func Wrap (ctx context.Context , err error , message string ) error {
41
57
return ErrCtx {ctx : ctx , err : errors .Wrap (err , message )}
42
58
}
43
59
60
+ // Wrapf is wrapping an error with the underneath errgo library
44
61
func Wrapf (ctx context.Context , err error , format string , args ... interface {}) error {
45
62
return ErrCtx {ctx : ctx , err : errors .Wrapf (err , format , args ... )}
46
63
}
47
64
48
- func Errorf (ctx context.Context , format string , args ... interface {}) error {
49
- return ErrCtx {ctx : ctx , err : errors .Errorf (format , args ... )}
50
- }
51
-
52
65
// RootCtxOrFallback unwrap all wrapped errors from err to get the deepest context
53
66
// from ErrCtx errors. If there is no wrapped ErrCtx RootCtxOrFallback returns ctx from parameter.
54
67
func RootCtxOrFallback (ctx context.Context , err error ) context.Context {
0 commit comments