File tree 2 files changed +19
-2
lines changed
2 files changed +19
-2
lines changed Original file line number Diff line number Diff line change 3
3
package postgres
4
4
5
5
import (
6
+ "context"
6
7
"errors"
7
8
"io"
8
9
"net"
@@ -13,14 +14,20 @@ import (
13
14
var ErrNotUnique = errors .New ("not unique" )
14
15
15
16
func IsErrConnectionFailed (err error ) bool {
17
+ // Context errors are checked separately otherwise they would be considered a network error.
18
+ if err == context .DeadlineExceeded || err == context .Canceled {
19
+ return false
20
+ }
21
+
16
22
// bun has this check internally for network errors
17
23
if errors .Is (err , io .EOF ) {
18
24
return true
19
25
}
20
26
27
+ var netError net.Error
28
+
21
29
// bun has this check internally for network errors
22
- _ , ok := err .(net.Error )
23
- if ok {
30
+ if ok := errors .As (err , & netError ); ok {
24
31
return true
25
32
}
26
33
Original file line number Diff line number Diff line change @@ -30,4 +30,14 @@ func TestIsErrConnectionFailed(t *testing.T) {
30
30
err := errors .New ("any other error" )
31
31
require .False (t , pbpostgres .IsErrConnectionFailed (err ))
32
32
})
33
+
34
+ t .Run ("context deadline exceeded error" , func (t * testing.T ) {
35
+ err := context .DeadlineExceeded
36
+ require .False (t , pbpostgres .IsErrConnectionFailed (err ))
37
+ })
38
+
39
+ t .Run ("context cancelled error" , func (t * testing.T ) {
40
+ err := context .Canceled
41
+ require .False (t , pbpostgres .IsErrConnectionFailed (err ))
42
+ })
33
43
}
You can’t perform that action at this time.
0 commit comments