Skip to content

Commit 053eecd

Browse files
committed
gitsrc: wrap errors for better reporting
1 parent 239bacc commit 053eecd

17 files changed

Lines changed: 722 additions & 16 deletions

File tree

Gopkg.lock

Lines changed: 15 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gitsrc/gitsrc.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,22 @@
22
package gitsrc
33

44
import (
5-
"errors"
6-
"fmt"
75
"time"
86

7+
"golang.org/x/xerrors"
98
"gopkg.in/src-d/go-git.v4"
109
"gopkg.in/urfave/cli.v1"
1110
"gopkg.in/urfave/cli.v1/altsrc"
1211
)
1312

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

17-
// ErrNotFound is returns when the String(name) doesn't have a reference
18-
var ErrNotFound = fmt.Errorf("key not found")
16+
// ErrNotFound is returned when the String(name) doesn't have a reference
17+
var ErrNotFound = xerrors.New("gitsrc: key not found")
18+
19+
// ErrNotBranch is returned when the git repo is not on a branch
20+
var ErrNotBranch = xerrors.New("gitsrc: ref is not a branch")
1921

2022
// FromCurrentDir tries to open $PWD as the git repo
2123
func FromCurrentDir(*cli.Context) (altsrc.InputSourceContext, error) {
@@ -33,26 +35,25 @@ func (x *gitSource) String(name string) (string, error) {
3335
case "git-origin":
3436
remote, err := x.Remote("origin")
3537
if err != nil {
36-
return "", err
38+
return "", xerrors.Errorf("gitsrc: %w", err)
3739
}
3840
return remote.Config().URLs[0], nil
3941
case "git-commit":
4042
ref, err := x.Head()
4143
if err != nil {
42-
return "", err
44+
return "", xerrors.Errorf("gitsrc: %w", err)
4345
}
4446
return ref.Hash().String(), nil
4547
case "git-branch":
4648
ref, err := x.Head()
4749
if err != nil {
48-
return "", err
50+
return "", xerrors.Errorf("gitsrc: %w", err)
4951
}
5052
refName := ref.Name()
5153
if refName.IsBranch() {
5254
return refName.String(), nil
53-
} else {
54-
return "", errors.New("Ref is not a branch")
5555
}
56+
return "", ErrNotBranch
5657
}
5758
return "", ErrNotFound
5859
}

vendor/golang.org/x/sys/windows/syscall_windows.go

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/golang.org/x/xerrors/LICENSE

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/golang.org/x/xerrors/PATENTS

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/golang.org/x/xerrors/README

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/golang.org/x/xerrors/adaptor_go1_12.go

Lines changed: 195 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)