forked from quic-go/quic-go
fix logging of application errors
This commit is contained in:
@@ -10,6 +10,7 @@ type QuicError struct {
|
||||
ErrorCode ErrorCode
|
||||
ErrorMessage string
|
||||
isTimeout bool
|
||||
isApplicationError bool
|
||||
}
|
||||
|
||||
var _ net.Error = &QuicError{}
|
||||
@@ -38,7 +39,21 @@ func CryptoError(tlsAlert uint8, errorMessage string) *QuicError {
|
||||
}
|
||||
}
|
||||
|
||||
func ApplicationError(errorCode ErrorCode, errorMessage string) *QuicError {
|
||||
return &QuicError{
|
||||
ErrorCode: errorCode,
|
||||
ErrorMessage: errorMessage,
|
||||
isApplicationError: true,
|
||||
}
|
||||
}
|
||||
|
||||
func (e *QuicError) Error() string {
|
||||
if e.isApplicationError {
|
||||
if len(e.ErrorMessage) == 0 {
|
||||
return fmt.Sprintf("Application error %#x", uint64(e.ErrorCode))
|
||||
}
|
||||
return fmt.Sprintf("Application error %#x: %s", uint64(e.ErrorCode), e.ErrorMessage)
|
||||
}
|
||||
if len(e.ErrorMessage) == 0 {
|
||||
return e.ErrorCode.Error()
|
||||
}
|
||||
|
||||
@@ -26,12 +26,12 @@ var _ = Describe("QUIC Transport Errors", func() {
|
||||
})
|
||||
|
||||
Context("crypto errors", func() {
|
||||
It("has a string representation for crypto errors with a message", func() {
|
||||
It("has a string representation for errors with a message", func() {
|
||||
err := CryptoError(42, "foobar")
|
||||
Expect(err.Error()).To(Equal("CRYPTO_ERROR: foobar"))
|
||||
})
|
||||
|
||||
It("has a string representation for crypto errors without a message", func() {
|
||||
It("has a string representation for errors without a message", func() {
|
||||
err := CryptoError(42, "")
|
||||
Expect(err.Error()).To(Equal("CRYPTO_ERROR: tls: bad certificate"))
|
||||
})
|
||||
@@ -42,6 +42,18 @@ var _ = Describe("QUIC Transport Errors", func() {
|
||||
})
|
||||
})
|
||||
|
||||
Context("application errors", func() {
|
||||
It("has a string representation for errors with a message", func() {
|
||||
err := ApplicationError(0x42, "foobar")
|
||||
Expect(err.Error()).To(Equal("Application error 0x42: foobar"))
|
||||
})
|
||||
|
||||
It("has a string representation for errors without a message", func() {
|
||||
err := ApplicationError(0x42, "")
|
||||
Expect(err.Error()).To(Equal("Application error 0x42"))
|
||||
})
|
||||
})
|
||||
|
||||
Context("ErrorCode", func() {
|
||||
It("works as error", func() {
|
||||
var err error = StreamStateError
|
||||
|
||||
12
session.go
12
session.go
@@ -685,7 +685,7 @@ func (s *session) handleFrame(f wire.Frame, pn protocol.PacketNumber, encLevel p
|
||||
case *wire.AckFrame:
|
||||
err = s.handleAckFrame(frame, pn, encLevel)
|
||||
case *wire.ConnectionCloseFrame:
|
||||
s.closeRemote(qerr.Error(frame.ErrorCode, frame.ReasonPhrase))
|
||||
s.handleConnectionCloseFrame(frame)
|
||||
case *wire.ResetStreamFrame:
|
||||
err = s.handleResetStreamFrame(frame)
|
||||
case *wire.MaxDataFrame:
|
||||
@@ -747,6 +747,16 @@ func (s *session) handlePacketAfterClosed(p *receivedPacket) {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *session) handleConnectionCloseFrame(frame *wire.ConnectionCloseFrame) {
|
||||
var e error
|
||||
if frame.IsApplicationError {
|
||||
e = qerr.ApplicationError(frame.ErrorCode, frame.ReasonPhrase)
|
||||
} else {
|
||||
e = qerr.Error(frame.ErrorCode, frame.ReasonPhrase)
|
||||
}
|
||||
s.closeRemote(e)
|
||||
}
|
||||
|
||||
func (s *session) handleCryptoFrame(frame *wire.CryptoFrame, encLevel protocol.EncryptionLevel) error {
|
||||
encLevelChanged, err := s.cryptoStreamManager.HandleCryptoFrame(frame, encLevel)
|
||||
if err != nil {
|
||||
|
||||
@@ -319,7 +319,7 @@ var _ = Describe("Session", func() {
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
})
|
||||
|
||||
It("handles CONNECTION_CLOSE frames", func() {
|
||||
It("handles CONNECTION_CLOSE frames, with a transport error code", func() {
|
||||
testErr := qerr.Error(qerr.StreamLimitError, "foobar")
|
||||
streamManager.EXPECT().CloseWithError(testErr)
|
||||
sessionRunner.EXPECT().Remove(gomock.Any())
|
||||
@@ -337,6 +337,26 @@ var _ = Describe("Session", func() {
|
||||
Expect(sess.handleFrame(ccf, 0, protocol.EncryptionUnspecified)).To(Succeed())
|
||||
Eventually(sess.Context().Done()).Should(BeClosed())
|
||||
})
|
||||
|
||||
It("handles CONNECTION_CLOSE frames, with an application error code", func() {
|
||||
testErr := qerr.ApplicationError(0x1337, "foobar")
|
||||
streamManager.EXPECT().CloseWithError(testErr)
|
||||
sessionRunner.EXPECT().Remove(gomock.Any())
|
||||
cryptoSetup.EXPECT().Close()
|
||||
|
||||
go func() {
|
||||
defer GinkgoRecover()
|
||||
cryptoSetup.EXPECT().RunHandshake().Do(func() { <-sess.Context().Done() })
|
||||
Expect(sess.run()).To(MatchError(testErr))
|
||||
}()
|
||||
ccf := &wire.ConnectionCloseFrame{
|
||||
ErrorCode: 0x1337,
|
||||
ReasonPhrase: "foobar",
|
||||
IsApplicationError: true,
|
||||
}
|
||||
Expect(sess.handleFrame(ccf, 0, protocol.EncryptionUnspecified)).To(Succeed())
|
||||
Eventually(sess.Context().Done()).Should(BeClosed())
|
||||
})
|
||||
})
|
||||
|
||||
It("tells its versions", func() {
|
||||
|
||||
Reference in New Issue
Block a user