Skip to content

Commit 8d62ebf

Browse files
Merge pull request #3163 from lucas-clemente/err-closed
use net.ErrClosed (for Go 1.16)
2 parents d97f03b + b384982 commit 8d62ebf

File tree

5 files changed

+110
-28
lines changed

5 files changed

+110
-28
lines changed

internal/qerr/quic_error.go renamed to internal/qerr/errors.go

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,6 @@ func NewCryptoError(tlsAlert uint8, errorMessage string) *TransportError {
2929
}
3030
}
3131

32-
func (e *TransportError) Is(target error) bool {
33-
_, ok := target.(*TransportError)
34-
return ok
35-
}
36-
3732
func (e *TransportError) Error() string {
3833
str := e.ErrorCode.String()
3934
if e.FrameType != 0 {
@@ -63,11 +58,6 @@ type ApplicationError struct {
6358

6459
var _ error = &ApplicationError{}
6560

66-
func (e *ApplicationError) Is(target error) bool {
67-
_, ok := target.(*ApplicationError)
68-
return ok
69-
}
70-
7161
func (e *ApplicationError) Error() string {
7262
if len(e.ErrorMessage) == 0 {
7363
return fmt.Sprintf("Application error %#x", e.ErrorCode)
@@ -82,10 +72,6 @@ var _ error = &IdleTimeoutError{}
8272
func (e *IdleTimeoutError) Timeout() bool { return true }
8373
func (e *IdleTimeoutError) Temporary() bool { return false }
8474
func (e *IdleTimeoutError) Error() string { return "timeout: no recent network activity" }
85-
func (e *IdleTimeoutError) Is(target error) bool {
86-
_, ok := target.(*IdleTimeoutError)
87-
return ok
88-
}
8975

9076
type HandshakeTimeoutError struct{}
9177

@@ -94,10 +80,6 @@ var _ error = &HandshakeTimeoutError{}
9480
func (e *HandshakeTimeoutError) Timeout() bool { return true }
9581
func (e *HandshakeTimeoutError) Temporary() bool { return false }
9682
func (e *HandshakeTimeoutError) Error() string { return "timeout: handshake did not complete in time" }
97-
func (e *HandshakeTimeoutError) Is(target error) bool {
98-
_, ok := target.(*HandshakeTimeoutError)
99-
return ok
100-
}
10183

10284
// A VersionNegotiationError occurs when the client and the server can't agree on a QUIC version.
10385
type VersionNegotiationError struct {
@@ -109,11 +91,6 @@ func (e *VersionNegotiationError) Error() string {
10991
return fmt.Sprintf("no compatible QUIC version found (we support %s, server offered %s)", e.Ours, e.Theirs)
11092
}
11193

112-
func (e *VersionNegotiationError) Is(target error) bool {
113-
_, ok := target.(*VersionNegotiationError)
114-
return ok
115-
}
116-
11794
// A StatelessResetError occurs when we receive a stateless reset.
11895
type StatelessResetError struct {
11996
Token protocol.StatelessResetToken
@@ -125,10 +102,5 @@ func (e *StatelessResetError) Error() string {
125102
return fmt.Sprintf("received a stateless reset with token %x", e.Token)
126103
}
127104

128-
func (e *StatelessResetError) Is(target error) bool {
129-
_, ok := target.(*StatelessResetError)
130-
return ok
131-
}
132-
133105
func (e *StatelessResetError) Timeout() bool { return false }
134106
func (e *StatelessResetError) Temporary() bool { return true }

internal/qerr/errors_go116.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// +build go1.16
2+
3+
package qerr
4+
5+
import (
6+
"net"
7+
)
8+
9+
func (e *TransportError) Is(target error) bool {
10+
_, ok := target.(*TransportError)
11+
if ok {
12+
return true
13+
}
14+
return target == net.ErrClosed
15+
}
16+
17+
func (e *ApplicationError) Is(target error) bool {
18+
_, ok := target.(*ApplicationError)
19+
if ok {
20+
return true
21+
}
22+
return target == net.ErrClosed
23+
}
24+
25+
func (e *IdleTimeoutError) Is(target error) bool {
26+
_, ok := target.(*IdleTimeoutError)
27+
if ok {
28+
return true
29+
}
30+
return target == net.ErrClosed
31+
}
32+
33+
func (e *HandshakeTimeoutError) Is(target error) bool {
34+
_, ok := target.(*HandshakeTimeoutError)
35+
if ok {
36+
return true
37+
}
38+
return target == net.ErrClosed
39+
}
40+
41+
func (e *VersionNegotiationError) Is(target error) bool {
42+
_, ok := target.(*VersionNegotiationError)
43+
if ok {
44+
return true
45+
}
46+
return target == net.ErrClosed
47+
}
48+
49+
func (e *StatelessResetError) Is(target error) bool {
50+
_, ok := target.(*StatelessResetError)
51+
if ok {
52+
return true
53+
}
54+
return target == net.ErrClosed
55+
}

internal/qerr/errors_go116_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// +build go1.16
2+
3+
package qerr
4+
5+
import (
6+
"errors"
7+
"net"
8+
9+
. "github.com/onsi/ginkgo"
10+
. "github.com/onsi/gomega"
11+
)
12+
13+
var _ = Describe("QUIC Errors", func() {
14+
It("says that errors are net.ErrClosed errors", func() {
15+
Expect(errors.Is(&TransportError{}, net.ErrClosed)).To(BeTrue())
16+
Expect(errors.Is(&ApplicationError{}, net.ErrClosed)).To(BeTrue())
17+
Expect(errors.Is(&IdleTimeoutError{}, net.ErrClosed)).To(BeTrue())
18+
Expect(errors.Is(&HandshakeTimeoutError{}, net.ErrClosed)).To(BeTrue())
19+
Expect(errors.Is(&StatelessResetError{}, net.ErrClosed)).To(BeTrue())
20+
Expect(errors.Is(&VersionNegotiationError{}, net.ErrClosed)).To(BeTrue())
21+
})
22+
})

internal/qerr/errors_not_go116.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// +build !go1.16
2+
3+
package qerr
4+
5+
func (e *TransportError) Is(target error) bool {
6+
_, ok := target.(*TransportError)
7+
return ok
8+
}
9+
10+
func (e *ApplicationError) Is(target error) bool {
11+
_, ok := target.(*ApplicationError)
12+
return ok
13+
}
14+
15+
func (e *IdleTimeoutError) Is(target error) bool {
16+
_, ok := target.(*IdleTimeoutError)
17+
return ok
18+
}
19+
20+
func (e *HandshakeTimeoutError) Is(target error) bool {
21+
_, ok := target.(*HandshakeTimeoutError)
22+
return ok
23+
}
24+
25+
func (e *VersionNegotiationError) Is(target error) bool {
26+
_, ok := target.(*VersionNegotiationError)
27+
return ok
28+
}
29+
30+
func (e *StatelessResetError) Is(target error) bool {
31+
_, ok := target.(*StatelessResetError)
32+
return ok
33+
}
File renamed without changes.

0 commit comments

Comments
 (0)