diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2015-10-28 15:02:25 +0100 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2015-10-28 15:02:25 +0100 |
commit | 419ea1639230c5a7613962cbcbe0eb8b9e1ad078 (patch) | |
tree | 5d62c97c8d29d4bef9f4892783ca446f4ee7cdab /clients/common | |
parent | 7d6c5a56c0b63705378f125523876de1a97fd1ce (diff) | |
download | go-git-419ea1639230c5a7613962cbcbe0eb8b9e1ad078.tar.gz |
clients: helpful error handling
Diffstat (limited to 'clients/common')
-rw-r--r-- | clients/common/common.go | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/clients/common/common.go b/clients/common/common.go index 4204cb7..d29706d 100644 --- a/clients/common/common.go +++ b/clients/common/common.go @@ -1,6 +1,7 @@ package common import ( + "errors" "fmt" "io/ioutil" "net/url" @@ -12,6 +13,10 @@ import ( "gopkg.in/sourcegraph/go-vcsurl.v1" ) +var ( + NotFoundErr = errors.New("repository not found") +) + const GitUploadPackServiceName = "git-upload-pack" type Endpoint string @@ -19,7 +24,7 @@ type Endpoint string func NewEndpoint(url string) (Endpoint, error) { vcs, err := vcsurl.Parse(url) if err != nil { - return "", err + return "", NewPermanentError(err) } link := vcs.Link() @@ -88,7 +93,7 @@ type GitUploadPackInfo struct { func NewGitUploadPackInfo(d *pktline.Decoder) (*GitUploadPackInfo, error) { info := &GitUploadPackInfo{} if err := info.read(d); err != nil { - return nil, err + return nil, NewUnexpectedError(err) } return info, nil @@ -164,3 +169,35 @@ func (r *GitUploadPackRequest) Reader() *strings.Reader { return e.Reader() } + +type PermanentError struct { + err error +} + +func NewPermanentError(err error) *PermanentError { + if err == nil { + return nil + } + + return &PermanentError{err: err} +} + +func (e *PermanentError) Error() string { + return fmt.Sprintf("permanent client error: %s", e.err.Error()) +} + +type UnexpectedError struct { + err error +} + +func NewUnexpectedError(err error) *UnexpectedError { + if err == nil { + return nil + } + + return &UnexpectedError{err: err} +} + +func (e *UnexpectedError) Error() string { + return fmt.Sprintf("unexpected client error: %s", e.err.Error()) +} |