diff options
Diffstat (limited to 'plumbing/protocol/packp/common.go')
-rw-r--r-- | plumbing/protocol/packp/common.go | 24 |
1 files changed, 24 insertions, 0 deletions
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) +} |