-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add context around checkout failures #210
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good so far, just a few minor issues!
gitclone/checkout_helper.go
Outdated
@@ -138,7 +139,8 @@ func mergeWithCustomRetry(gitCmd git.Git, arg string, retry fallbackRetry) error | |||
return runner.Run(gitCmd.Merge(arg)) | |||
} | |||
|
|||
return fmt.Errorf("merge failed (%s): %v", arg, mErr) | |||
wErr := fmt.Errorf("merge failed (%s): %w%w", arg, mErr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm we're trying to read the error output from the command, but I guess git
doesn't treat this scenario as an error in its logging even though it exits with exit status 1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added additional messaging for this scenario: 244e94f
@@ -43,7 +43,7 @@ func (c checkoutPRMergeRef) do(gitCmd git.Git, fetchOpts fetchOptions, fallback | |||
// $ git fetch origin refs/remotes/pull/7/merge:refs/pull/7/merge | |||
err := fetch(gitCmd, originRemoteName, refSpec, fetchOpts) | |||
if err != nil { | |||
return err | |||
return fmt.Errorf("failed to fetch merge ref: %w", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -43,7 +43,7 @@ type checkoutPRDiffFile struct { | |||
func (c checkoutPRDiffFile) do(gitCmd git.Git, fetchOptions fetchOptions, fallback fallbackRetry) error { | |||
destBranchRef := refsHeadsPrefix + c.params.DestinationBranch | |||
if err := fetch(gitCmd, originRemoteName, destBranchRef, fetchOptions); err != nil { | |||
return err | |||
return fmt.Errorf("failed to fetch base branch: %w", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -62,7 +62,7 @@ func (c checkoutPRManualMerge) do(gitCmd git.Git, fetchOptions fetchOptions, fal | |||
// Fetch and checkout destinations branch | |||
destBranchRef := refsHeadsPrefix + c.params.DestinationBranch | |||
if err := fetchInitialBranch(gitCmd, originRemoteName, destBranchRef, fetchOptions); err != nil { | |||
return err | |||
return fmt.Errorf("failed to fetch base branch: %w", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -87,7 +87,7 @@ func (c checkoutPRManualMerge) do(gitCmd git.Git, fetchOptions fetchOptions, fal | |||
// Fetch and merge | |||
sourceBranchRef := refsHeadsPrefix + c.params.SourceBranch | |||
if err := fetch(gitCmd, remoteName, sourceBranchRef, fetchOptions); err != nil { | |||
return err | |||
return fmt.Errorf("failed to fetch compare branch: %w", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: The formatting is a bit messed up because the steperror package in go-steputils v1 does not have the error unwrapping interface implemented. This is how it looks with those changes in place: I opened a PR in go-steputils to add this: bitrise-io/go-steputils#77 |
return err | ||
err = fmt.Errorf("failed to checkout commit: %w", err) | ||
newErr := fmt.Errorf("please check if the provided commit hash (%s) is valid", c.params.Commit) | ||
return fmt.Errorf("%v: %w", err, newErr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -72,7 +73,7 @@ func fetch(gitCmd git.Git, remote string, ref string, options fetchOptions) erro | |||
return handleCheckoutError( | |||
listBranches(gitCmd), | |||
fetchFailedTag, | |||
fmt.Errorf("fetch failed: %v", err), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing fetch failed:
from here since the caller of this method has more context on what went wrong we add additional error messaging at the various call sites instead.
@@ -101,7 +102,8 @@ func checkoutWithCustomRetry(gitCmd git.Git, arg string, retry fallbackRetry) er | |||
func fetchInitialBranch(gitCmd git.Git, remote string, branchRef string, fetchTraits fetchOptions) error { | |||
branch := strings.TrimPrefix(branchRef, refsHeadsPrefix) | |||
if err := fetch(gitCmd, remote, branchRef, fetchTraits); err != nil { | |||
return err | |||
wErr := fmt.Errorf("failed to fetch branch (%s): %w", branchRef, err) | |||
return fmt.Errorf("%v: %w", wErr, errors.New("please make sure the branch still exists")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gitclone/checkout_helper.go
Outdated
@@ -119,7 +121,7 @@ func fetchInitialBranch(gitCmd git.Git, remote string, branchRef string, fetchTr | |||
if err := runner.Run(gitCmd.Merge(remoteBranch)); err != nil { | |||
return newStepError( | |||
"update_branch_failed", | |||
fmt.Errorf("updating branch (merge) failed %s: %v", branch, err), | |||
fmt.Errorf("updating branch (merge) failed %s: %w", branch, err), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Co-authored-by: Olivér Falvai <oliver.falvai@bitrise.io>
Co-authored-by: Olivér Falvai <oliver.falvai@bitrise.io>
Co-authored-by: Olivér Falvai <oliver.falvai@bitrise.io>
Co-authored-by: Olivér Falvai <oliver.falvai@bitrise.io>
Co-authored-by: lpusok <7979773+lpusok@users.noreply.github.com>
Co-authored-by: Olivér Falvai <oliver.falvai@bitrise.io>
Checklist
step.yml
andREADME.md
is updated with the changes (if needed)Version
Requires a PATCH version update
Context
[CI-620] We want to improve the readability of error messages and suggest to users actions they can take to more quickly resolve build failures.
Changes
Investigation details
Decisions