File tree Expand file tree Collapse file tree 2 files changed +30
-9
lines changed Expand file tree Collapse file tree 2 files changed +30
-9
lines changed Original file line number Diff line number Diff line change @@ -70,15 +70,9 @@ func (t temporary) Temporary() bool { return true }
70
70
// IsTemporary returns true if the error or a recursive cause returns true for
71
71
// temporary.
72
72
func IsTemporary (err error ) bool {
73
- if tmp , ok := err .(Temporary ); ok && tmp .Temporary () {
74
- return true
73
+ var tmp Temporary
74
+ if errors .As (err , & tmp ) {
75
+ return tmp .Temporary ()
75
76
}
76
-
77
- cause := errors .Cause (err )
78
-
79
- if tmp , ok := cause .(Temporary ); ok && tmp .Temporary () {
80
- return true
81
- }
82
-
83
77
return false
84
78
}
Original file line number Diff line number Diff line change
1
+ package exec
2
+
3
+ import (
4
+ "fmt"
5
+ "testing"
6
+
7
+ "github.com/pkg/errors"
8
+ )
9
+
10
+ func TestIsTemporary (t * testing.T ) {
11
+ err := fmt .Errorf ("err" )
12
+ err1 := MakeTemporary (fmt .Errorf ("err1: %w" , err ))
13
+ err2 := fmt .Errorf ("err2: %w" , err1 )
14
+ err3 := errors .Wrap (err2 , "err3" )
15
+ err4 := fmt .Errorf ("err4: %w" , err3 )
16
+ err5 := errors .Wrap (err4 , "err5" )
17
+
18
+ if IsTemporary (nil ) {
19
+ t .Error ("expected error to not be a temporary error" )
20
+ }
21
+ if IsTemporary (err ) {
22
+ t .Error ("expected error to not be a temporary error" )
23
+ }
24
+ if ! IsTemporary (err5 ) {
25
+ t .Error ("expected error to be a temporary error" )
26
+ }
27
+ }
You can’t perform that action at this time.
0 commit comments