Skip to content

Commit bc38a23

Browse files
committed
codec: bufioDecReader: checkErr before halting with io.ErrUnexpectedEOF
This way, we bubble up the right tracked error if available. Fixes #421
1 parent 175ab60 commit bc38a23

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

codec/reader.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,12 @@ func (z *ioDecReader) checkErr() {
202202
halt.onerror(z.readErr())
203203
}
204204

205+
func (z *ioDecReader) unexpectedEOF() {
206+
z.checkErr()
207+
// if no error, still halt with unexpected EOF
208+
halt.error(io.ErrUnexpectedEOF)
209+
}
210+
205211
func (z *ioDecReader) readOne() (b byte, err error) {
206212
n, err := z.r.Read(z.b[:])
207213
if n == 1 {
@@ -543,12 +549,12 @@ func (z *ioDecReader) skipWhitespace() (tok byte) {
543549
BUFIO:
544550
if pos == z.wc {
545551
if z.done {
546-
halt.onerror(io.ErrUnexpectedEOF)
552+
z.unexpectedEOF()
547553
}
548554
numshift, numread := z.fillbuf(0)
549555
pos -= numshift
550556
if numread == 0 {
551-
halt.onerror(io.ErrUnexpectedEOF)
557+
z.unexpectedEOF()
552558
}
553559
}
554560
tok = z.buf[pos]
@@ -588,13 +594,13 @@ func (z *ioDecReader) readUntil(stop1, stop2 byte) (bs []byte, tok byte) {
588594
BUFIO:
589595
if pos == z.wc {
590596
if z.done {
591-
halt.onerror(io.ErrUnexpectedEOF)
597+
z.unexpectedEOF()
592598
}
593599
numshift, numread := z.fillbuf(0)
594600
start -= numshift
595601
pos -= numshift
596602
if numread == 0 {
597-
halt.onerror(io.ErrUnexpectedEOF)
603+
z.unexpectedEOF()
598604
}
599605
}
600606
tok = z.buf[pos]

0 commit comments

Comments
 (0)