Skip to content

Commit a43d9a6

Browse files
committed
git: fix error wrapping to ensure internal errors are propogated
Also, tidy up the error printing, so that now we always print out the "current commit information was not captured by the build" message, instead of just for not locating the git binary. Before: WARNING: buildx: git was not found in the system. Current commit information was not captured by the build After: WARNING: current commit information was not captured by the build: git was not found in the system: <error message> Signed-off-by: Justin Chadwell <me@jedevc.com>
1 parent c47eb3b commit a43d9a6

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

build/build.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ func BuildWithResultHandler(ctx context.Context, nodes []builder.Node, opt map[s
737737
hasMobyDriver := false
738738
gitattrs, err := getGitAttributes(ctx, opt.Inputs.ContextPath, opt.Inputs.DockerfilePath)
739739
if err != nil {
740-
logrus.Warn(err)
740+
logrus.WithError(err).Warn("current commit information was not captured by the build")
741741
}
742742
for i, np := range m[k] {
743743
node := nodes[np.driverIndex]

build/git.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,21 @@ func getGitAttributes(ctx context.Context, contextPath string, dockerfilePath st
5151

5252
gitc, err := gitutil.New(gitutil.WithContext(ctx), gitutil.WithWorkingDir(wd))
5353
if err != nil {
54-
if st, err := os.Stat(path.Join(wd, ".git")); err == nil && st.IsDir() {
55-
return res, errors.New("buildx: git was not found in the system. Current commit information was not captured by the build")
54+
if st, err1 := os.Stat(path.Join(wd, ".git")); err1 == nil && st.IsDir() {
55+
return res, errors.Wrap(err, "git was not found in the system")
5656
}
5757
return
5858
}
5959

6060
if !gitc.IsInsideWorkTree() {
6161
if st, err := os.Stat(path.Join(wd, ".git")); err == nil && st.IsDir() {
62-
return res, errors.New("buildx: failed to read current commit information with git rev-parse --is-inside-work-tree")
62+
return res, errors.New("failed to read current commit information with git rev-parse --is-inside-work-tree")
6363
}
6464
return res, nil
6565
}
6666

6767
if sha, err := gitc.FullCommit(); err != nil && !gitutil.IsUnknownRevision(err) {
68-
return res, errors.Wrapf(err, "buildx: failed to get git commit")
68+
return res, errors.Wrap(err, "failed to get git commit")
6969
} else if sha != "" {
7070
checkDirty := false
7171
if v, ok := os.LookupEnv("BUILDX_GIT_CHECK_DIRTY"); ok {
@@ -95,7 +95,7 @@ func getGitAttributes(ctx context.Context, contextPath string, dockerfilePath st
9595

9696
if setGitLabels {
9797
if root, err := gitc.RootDir(); err != nil {
98-
return res, errors.Wrapf(err, "buildx: failed to get git root dir")
98+
return res, errors.Wrap(err, "failed to get git root dir")
9999
} else if root != "" {
100100
if dockerfilePath == "" {
101101
dockerfilePath = filepath.Join(wd, "Dockerfile")

0 commit comments

Comments
 (0)