Skip to content
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

Merged
merged 20 commits into from
Mar 20, 2023
Merged

Add context around checkout failures #210

merged 20 commits into from
Mar 20, 2023

Conversation

vshah23
Copy link
Contributor

@vshah23 vshah23 commented Mar 8, 2023

Checklist

  • I've read and followed the Contribution Guidelines
  • step.yml and README.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

  • Add context around checkout failures
  • Added suggestions for fetch failures

Investigation details

Decisions

Copy link
Contributor

@ofalvai ofalvai left a 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!

@@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I incidentally stumbled into exactly this kind of error in CI a few hours ago 😆 Looks like the mErr variable is empty, while you are at it, can you look into why this is printed like this? Don't spend too much time on it if it's not an obvious issue, I just wanted to highlight 😇

image

Copy link
Contributor Author

@vshah23 vshah23 Mar 20, 2023

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

Copy link
Contributor Author

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

The output looks like:
image

gitclone/checkout_helper.go Outdated Show resolved Hide resolved
@vshah23 vshah23 marked this pull request as ready for review March 9, 2023 13:54
godrei
godrei previously approved these changes Mar 13, 2023
gitclone/checkout_helper.go Outdated Show resolved Hide resolved
@@ -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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

@@ -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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

@@ -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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

@@ -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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

@vshah23
Copy link
Contributor Author

vshah23 commented Mar 15, 2023

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:
image

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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

@@ -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),
Copy link
Contributor Author

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"))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

@@ -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),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

vshah23 and others added 9 commits March 20, 2023 08:47
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>
@vshah23 vshah23 requested a review from ofalvai March 20, 2023 15:50
@vshah23 vshah23 merged commit f29bfca into master Mar 20, 2023
@vshah23 vshah23 deleted the CI-620 branch March 20, 2023 16:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants