File tree Expand file tree Collapse file tree 3 files changed +5
-36
lines changed Expand file tree Collapse file tree 3 files changed +5
-36
lines changed Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ type causer interface {
13
13
// If you want get direct cause, use DirectCause.
14
14
// If error is nil, it will return nil. If error is not wrapped it will return the error itself.
15
15
// error wrapped using https://github.com/pkg/errors also satisfies this interface and can be unwrapped as well.
16
- // TODO: might consider rename it to Unwrap since we are deprecating causer interface
16
+ // Deprecated: Use Walk if you need root cause or Unwrap if you need direct cause.
17
17
func Cause (err error ) error {
18
18
if err == nil {
19
19
return nil
@@ -29,21 +29,4 @@ func Cause(err error) error {
29
29
}
30
30
}
31
31
return err
32
- }
33
-
34
- // DirectCause returns the direct cause of the error (if any).
35
- // It does NOT follow the cause chain all the way down, just the first one (if any),
36
- // If you want to get root cause, use Cause
37
- func DirectCause (err error ) error {
38
- if err == nil {
39
- return nil
40
- }
41
- switch err .(type ) {
42
- case Wrapper :
43
- return err .(Wrapper ).Unwrap ()
44
- case causer :
45
- return err .(causer ).Cause ()
46
- default :
47
- return err
48
- }
49
- }
32
+ }
Original file line number Diff line number Diff line change @@ -21,18 +21,4 @@ func TestCause(t *testing.T) {
21
21
22
22
stderr := stderrors .New ("std" )
23
23
assert .Equal (t , stderr , errors .Cause (stderr ))
24
- }
25
-
26
- func TestDirectCause (t * testing.T ) {
27
- assert .Nil (t , errors .DirectCause (nil ))
28
-
29
- errw := errors .Wrap (os .ErrClosed , "can't open closed file" )
30
- errww := errors .Wrap (errw , "wrap again" )
31
- assert .Equal (t , os .ErrClosed , errors .Cause (errww ))
32
- assert .Equal (t , os .ErrClosed , errors .Cause (errw ))
33
- assert .NotEqual (t , os .ErrClosed , errors .DirectCause (errww ))
34
- assert .Equal (t , "can't open closed file" , errors .DirectCause (errww ).(errors.Messenger ).Message ())
35
-
36
- stderr := stderrors .New ("std" )
37
- assert .Equal (t , stderr , errors .DirectCause (stderr ))
38
- }
24
+ }
Original file line number Diff line number Diff line change 6
6
7
7
// inspect.go defines functions for inspecting wrapped error or error list
8
8
9
- // Unwrap returns the underlying error. If the error is not wrapped, it returns nil.
10
- // Its behavior is same as standard library.
9
+ // Unwrap returns the first underlying error. If the error is not wrapped, it returns nil.
10
+ // It does NOT follow the entire error chain. Its behavior is same as standard library.
11
11
func Unwrap (err error ) error {
12
12
if err == nil {
13
13
return nil
You can’t perform that action at this time.
0 commit comments