include the frame type in the QuicError error message

This commit is contained in:
Marten Seemann
2019-11-08 12:54:05 +07:00
parent 2c2b5da612
commit 76c742a43d
3 changed files with 41 additions and 4 deletions

View File

@@ -8,6 +8,7 @@ import (
// A QuicError consists of an error code plus a error reason
type QuicError struct {
ErrorCode ErrorCode
FrameType uint64 // only valid if this not an application error
ErrorMessage string
isTimeout bool
isApplicationError bool
@@ -23,6 +24,15 @@ func Error(errorCode ErrorCode, errorMessage string) *QuicError {
}
}
// ErrorWithFrameType creates a new QuicError instance for a specific frame type
func ErrorWithFrameType(errorCode ErrorCode, frameType uint64, errorMessage string) *QuicError {
return &QuicError{
ErrorCode: errorCode,
FrameType: frameType,
ErrorMessage: errorMessage,
}
}
// TimeoutError creates a new QuicError instance for a timeout error
func TimeoutError(errorMessage string) *QuicError {
return &QuicError{
@@ -55,10 +65,18 @@ func (e *QuicError) Error() string {
}
return fmt.Sprintf("Application error %#x: %s", uint64(e.ErrorCode), e.ErrorMessage)
}
if len(e.ErrorMessage) == 0 {
return e.ErrorCode.Error()
str := e.ErrorCode.String()
if e.FrameType != 0 {
str += fmt.Sprintf(" (frame type: %#x)", e.FrameType)
}
return fmt.Sprintf("%s: %s", e.ErrorCode.String(), e.ErrorMessage)
msg := e.ErrorMessage
if len(msg) == 0 {
msg = e.ErrorCode.Message()
}
if len(msg) == 0 {
return str
}
return str + ": " + msg
}
// IsCryptoError says if this error is a crypto error