include the frame type in the error returned by the frame parser

This commit is contained in:
Marten Seemann 2019-11-08 14:01:27 +07:00
parent 76c742a43d
commit dbdccfa70a
2 changed files with 4 additions and 3 deletions

View file

@ -2,6 +2,7 @@ package wire
import (
"bytes"
"errors"
"fmt"
"reflect"
@ -32,7 +33,7 @@ func (p *frameParser) ParseNext(r *bytes.Reader, encLevel protocol.EncryptionLev
f, err := p.parseFrame(r, typeByte, encLevel)
if err != nil {
return nil, qerr.Error(qerr.FrameEncodingError, err.Error())
return nil, qerr.ErrorWithFrameType(qerr.FrameEncodingError, uint64(typeByte), err.Error())
}
return f, nil
}
@ -85,7 +86,7 @@ func (p *frameParser) parseFrame(r *bytes.Reader, typeByte byte, encLevel protoc
case 0x1c, 0x1d:
frame, err = parseConnectionCloseFrame(r, p.version)
default:
err = fmt.Errorf("unknown type byte 0x%x", typeByte)
err = errors.New("unknown frame type")
}
}
if err != nil {

View file

@ -273,7 +273,7 @@ var _ = Describe("Frame parsing", func() {
It("errors on invalid type", func() {
_, err := parser.ParseNext(bytes.NewReader([]byte{0x42}), protocol.Encryption1RTT)
Expect(err).To(MatchError("FRAME_ENCODING_ERROR: unknown type byte 0x42"))
Expect(err).To(MatchError("FRAME_ENCODING_ERROR (frame type: 0x42): unknown frame type"))
})
It("errors on invalid frames", func() {