aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/format/pktline
diff options
context:
space:
mode:
Diffstat (limited to 'plumbing/format/pktline')
-rw-r--r--plumbing/format/pktline/scanner.go7
-rw-r--r--plumbing/format/pktline/scanner_test.go11
2 files changed, 15 insertions, 3 deletions
diff --git a/plumbing/format/pktline/scanner.go b/plumbing/format/pktline/scanner.go
index 3ce2adf..4eec18c 100644
--- a/plumbing/format/pktline/scanner.go
+++ b/plumbing/format/pktline/scanner.go
@@ -80,10 +80,11 @@ func (s *Scanner) Bytes() []byte {
// pkt-len and substracting the pkt-len size.
func (s *Scanner) readPayloadLen() (int, error) {
if _, err := io.ReadFull(s.r, s.len[:]); err != nil {
- if err == io.EOF {
- return 0, err
+ if err == io.ErrUnexpectedEOF {
+ return 0, ErrInvalidPktLen
}
- return 0, ErrInvalidPktLen
+
+ return 0, err
}
n, err := hexDecode(s.len)
diff --git a/plumbing/format/pktline/scanner_test.go b/plumbing/format/pktline/scanner_test.go
index 9f440a4..b8a78ec 100644
--- a/plumbing/format/pktline/scanner_test.go
+++ b/plumbing/format/pktline/scanner_test.go
@@ -2,6 +2,7 @@ package pktline_test
import (
"bytes"
+ "errors"
"fmt"
"io"
"strings"
@@ -145,6 +146,16 @@ func (s *SuiteScanner) TestEOF(c *C) {
c.Assert(sc.Err(), IsNil)
}
+type mockReader struct{}
+
+func (r *mockReader) Read([]byte) (int, error) { return 0, errors.New("foo") }
+
+func (s *SuiteScanner) TestInternalReadError(c *C) {
+ sc := pktline.NewScanner(&mockReader{})
+ c.Assert(sc.Scan(), Equals, false)
+ c.Assert(sc.Err(), ErrorMatches, "foo")
+}
+
// A section are several non flush-pkt lines followed by a flush-pkt, which
// how the git protocol sends long messages.
func (s *SuiteScanner) TestReadSomeSections(c *C) {