From df9748cfb51db9c406e3df063badbd8c78ee819d Mon Sep 17 00:00:00 2001 From: Máximo Cuadros Date: Mon, 12 Dec 2016 15:50:15 +0100 Subject: transport: new git protocol (#175) --- plumbing/protocol/packp/common.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'plumbing/protocol/packp/common.go') 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) +} -- cgit