Skip to content

Commit

Permalink
gitsrc: wrap errors for better reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
zimbatm committed May 1, 2019
1 parent 239bacc commit 053eecd
Show file tree
Hide file tree
Showing 17 changed files with 722 additions and 16 deletions.
18 changes: 15 additions & 3 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 11 additions & 10 deletions gitsrc/gitsrc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,22 @@
package gitsrc

import (
"errors"
"fmt"
"time"

"golang.org/x/xerrors"
"gopkg.in/src-d/go-git.v4"
"gopkg.in/urfave/cli.v1"
"gopkg.in/urfave/cli.v1/altsrc"
)

// ErrNotSupported is returned by all the functions that are not String()
var ErrNotSupported = fmt.Errorf("operation not supported")
var ErrNotSupported = xerrors.New("gitsrc: operation not supported")

// ErrNotFound is returns when the String(name) doesn't have a reference
var ErrNotFound = fmt.Errorf("key not found")
// ErrNotFound is returned when the String(name) doesn't have a reference
var ErrNotFound = xerrors.New("gitsrc: key not found")

// ErrNotBranch is returned when the git repo is not on a branch
var ErrNotBranch = xerrors.New("gitsrc: ref is not a branch")

// FromCurrentDir tries to open $PWD as the git repo
func FromCurrentDir(*cli.Context) (altsrc.InputSourceContext, error) {
Expand All @@ -33,26 +35,25 @@ func (x *gitSource) String(name string) (string, error) {
case "git-origin":
remote, err := x.Remote("origin")
if err != nil {
return "", err
return "", xerrors.Errorf("gitsrc: %w", err)
}
return remote.Config().URLs[0], nil
case "git-commit":
ref, err := x.Head()
if err != nil {
return "", err
return "", xerrors.Errorf("gitsrc: %w", err)
}
return ref.Hash().String(), nil
case "git-branch":
ref, err := x.Head()
if err != nil {
return "", err
return "", xerrors.Errorf("gitsrc: %w", err)
}
refName := ref.Name()
if refName.IsBranch() {
return refName.String(), nil
} else {
return "", errors.New("Ref is not a branch")
}
return "", ErrNotBranch
}
return "", ErrNotFound
}
Expand Down
3 changes: 0 additions & 3 deletions vendor/golang.org/x/sys/windows/syscall_windows.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions vendor/golang.org/x/xerrors/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions vendor/golang.org/x/xerrors/PATENTS

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions vendor/golang.org/x/xerrors/README

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

195 changes: 195 additions & 0 deletions vendor/golang.org/x/xerrors/adaptor_go1_12.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 053eecd

Please sign in to comment.