From fefdea34205fec1f792007b24661ab87d9c01ca8 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Mon, 31 Aug 2020 14:47:33 +0700 Subject: [PATCH] use the os.ErrDeadlineExceeded for stream deadline errors on Go 1.15 --- stream.go | 9 --------- stream_deadline_error.go | 11 +++++++++++ stream_deadline_error_go115.go | 9 +++++++++ stream_deadline_error_test.go | 21 +++++++++++++++++++++ 4 files changed, 41 insertions(+), 9 deletions(-) create mode 100644 stream_deadline_error.go create mode 100644 stream_deadline_error_go115.go create mode 100644 stream_deadline_error_test.go diff --git a/stream.go b/stream.go index c98ac8d5..a1c5fecc 100644 --- a/stream.go +++ b/stream.go @@ -1,7 +1,6 @@ package quic import ( - "net" "sync" "time" @@ -74,14 +73,6 @@ type stream struct { var _ Stream = &stream{} -type deadlineError struct{} - -func (deadlineError) Error() string { return "deadline exceeded" } -func (deadlineError) Temporary() bool { return true } -func (deadlineError) Timeout() bool { return true } - -var errDeadline net.Error = &deadlineError{} - type streamCanceledError struct { error errorCode protocol.ApplicationErrorCode diff --git a/stream_deadline_error.go b/stream_deadline_error.go new file mode 100644 index 00000000..f7f97a34 --- /dev/null +++ b/stream_deadline_error.go @@ -0,0 +1,11 @@ +package quic + +import "net" + +type deadlineError struct{} + +func (deadlineError) Error() string { return "deadline exceeded" } +func (deadlineError) Temporary() bool { return true } +func (deadlineError) Timeout() bool { return true } + +var errDeadline net.Error = &deadlineError{} diff --git a/stream_deadline_error_go115.go b/stream_deadline_error_go115.go new file mode 100644 index 00000000..db371b93 --- /dev/null +++ b/stream_deadline_error_go115.go @@ -0,0 +1,9 @@ +// +build go1.15 + +package quic + +import ( + "os" +) + +func (deadlineError) Unwrap() error { return os.ErrDeadlineExceeded } diff --git a/stream_deadline_error_test.go b/stream_deadline_error_test.go new file mode 100644 index 00000000..a1f178a5 --- /dev/null +++ b/stream_deadline_error_test.go @@ -0,0 +1,21 @@ +// +build go1.15 + +package quic + +import ( + "errors" + "os" + + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" +) + +var _ = Describe("Deadline Error", func() { + It("is a net.Error that wraps os.ErrDeadlineError", func() { + err := deadlineError{} + Expect(err.Temporary()).To(BeTrue()) + Expect(err.Timeout()).To(BeTrue()) + Expect(errors.Is(err, os.ErrDeadlineExceeded)).To(BeTrue()) + Expect(errors.Unwrap(err)).To(Equal(os.ErrDeadlineExceeded)) + }) +})