forked from quic-go/quic-go
expose a VersionNegoationError
This commit is contained in:
@@ -2,6 +2,8 @@ package qerr
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/lucas-clemente/quic-go/internal/protocol"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -92,3 +94,18 @@ func (e *HandshakeTimeoutError) Is(target error) bool {
|
||||
_, ok := target.(*HandshakeTimeoutError)
|
||||
return ok
|
||||
}
|
||||
|
||||
// A VersionNegotiationError occurs when the client and the server can't agree on a QUIC version.
|
||||
type VersionNegotiationError struct {
|
||||
Ours []protocol.VersionNumber
|
||||
Theirs []protocol.VersionNumber
|
||||
}
|
||||
|
||||
func (e *VersionNegotiationError) Error() string {
|
||||
return fmt.Sprintf("no compatible QUIC version found (we support %s, server offered %s)", e.Ours, e.Theirs)
|
||||
}
|
||||
|
||||
func (e *VersionNegotiationError) Is(target error) bool {
|
||||
_, ok := target.(*VersionNegotiationError)
|
||||
return ok
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"errors"
|
||||
"net"
|
||||
|
||||
"github.com/lucas-clemente/quic-go/internal/protocol"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
@@ -101,4 +102,17 @@ var _ = Describe("QUIC Errors", func() {
|
||||
Expect(errors.Is(err, &IdleTimeoutError{})).To(BeTrue())
|
||||
})
|
||||
})
|
||||
|
||||
Context("Version Negotiation errors", func() {
|
||||
It("is a Version Negotiation error", func() {
|
||||
Expect(errors.Is(&VersionNegotiationError{Ours: []protocol.VersionNumber{2, 3}}, &VersionNegotiationError{})).To(BeTrue())
|
||||
})
|
||||
|
||||
It("has a string representation", func() {
|
||||
Expect((&VersionNegotiationError{
|
||||
Ours: []protocol.VersionNumber{2, 3},
|
||||
Theirs: []protocol.VersionNumber{4, 5, 6},
|
||||
}).Error()).To(Equal("no compatible QUIC version found (we support [0x2 0x3], server offered [0x4 0x5 0x6])"))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user