diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2016-12-12 15:50:15 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-12-12 15:50:15 +0100 |
commit | df9748cfb51db9c406e3df063badbd8c78ee819d (patch) | |
tree | c03578daefa14b14ca480c3e801ee8e225599b22 /plumbing/protocol | |
parent | 3967812bd0de40330dfbb9e1a7d14d4073cc1b10 (diff) | |
download | go-git-df9748cfb51db9c406e3df063badbd8c78ee819d.tar.gz |
transport: new git protocol (#175)
Diffstat (limited to 'plumbing/protocol')
-rw-r--r-- | plumbing/protocol/packp/advrefs_decode.go | 8 | ||||
-rw-r--r-- | plumbing/protocol/packp/advrefs_decode_test.go | 2 | ||||
-rw-r--r-- | plumbing/protocol/packp/common.go | 24 | ||||
-rw-r--r-- | plumbing/protocol/packp/ulreq_decode.go | 8 |
4 files changed, 37 insertions, 5 deletions
diff --git a/plumbing/protocol/packp/advrefs_decode.go b/plumbing/protocol/packp/advrefs_decode.go index fddd69b..e0a449e 100644 --- a/plumbing/protocol/packp/advrefs_decode.go +++ b/plumbing/protocol/packp/advrefs_decode.go @@ -55,8 +55,12 @@ type decoderStateFn func(*advRefsDecoder) decoderStateFn // fills out the parser stiky error func (d *advRefsDecoder) error(format string, a ...interface{}) { - d.err = fmt.Errorf("pkt-line %d: %s", d.nLine, - fmt.Sprintf(format, a...)) + msg := fmt.Sprintf( + "pkt-line %d: %s", d.nLine, + fmt.Sprintf(format, a...), + ) + + d.err = NewErrUnexpectedData(msg, d.line) } // Reads a new pkt-line from the scanner, makes its payload available as diff --git a/plumbing/protocol/packp/advrefs_decode_test.go b/plumbing/protocol/packp/advrefs_decode_test.go index 2cc2568..e9a01f8 100644 --- a/plumbing/protocol/packp/advrefs_decode_test.go +++ b/plumbing/protocol/packp/advrefs_decode_test.go @@ -46,7 +46,7 @@ func (s *AdvRefsDecodeSuite) TestShortForHash(c *C) { pktline.FlushString, } r := toPktLines(c, payloads) - s.testDecoderErrorMatches(c, r, ".*too short") + s.testDecoderErrorMatches(c, r, ".*too short.*") } func (s *AdvRefsDecodeSuite) testDecoderErrorMatches(c *C, input io.Reader, pattern string) { diff --git a/plumbing/protocol/packp/common.go b/plumbing/protocol/packp/common.go index 93dfaed..ab07ac8 100644 --- a/plumbing/protocol/packp/common.go +++ b/plumbing/protocol/packp/common.go @@ -1,5 +1,9 @@ package packp +import ( + "fmt" +) + type stateFn func() stateFn const ( @@ -44,3 +48,23 @@ var ( func isFlush(payload []byte) bool { return len(payload) == 0 } + +// ErrUnexpectedData represents an unexpected data decoding a message +type ErrUnexpectedData struct { + Msg string + Data []byte +} + +// NewErrUnexpectedData returns a new ErrUnexpectedData containing the data and +// the message given +func NewErrUnexpectedData(msg string, data []byte) error { + return &ErrUnexpectedData{Msg: msg, Data: data} +} + +func (err *ErrUnexpectedData) Error() string { + if len(err.Data) == 0 { + return err.Msg + } + + return fmt.Sprintf("%s (%s)", err.Msg, err.Data) +} diff --git a/plumbing/protocol/packp/ulreq_decode.go b/plumbing/protocol/packp/ulreq_decode.go index 541a077..bcd642d 100644 --- a/plumbing/protocol/packp/ulreq_decode.go +++ b/plumbing/protocol/packp/ulreq_decode.go @@ -45,8 +45,12 @@ func (d *ulReqDecoder) Decode(v *UploadRequest) error { // fills out the parser stiky error func (d *ulReqDecoder) error(format string, a ...interface{}) { - d.err = fmt.Errorf("pkt-line %d: %s", d.nLine, - fmt.Sprintf(format, a...)) + msg := fmt.Sprintf( + "pkt-line %d: %s", d.nLine, + fmt.Sprintf(format, a...), + ) + + d.err = NewErrUnexpectedData(msg, d.line) } // Reads a new pkt-line from the scanner, makes its payload available as |