Merge pull request #250 from github/no-errors-wrap

Migrate away from `errors.Wrap()`
This commit is contained in:
Nate Smith 2020-01-23 09:51:47 -06:00 committed by GitHub
commit 11bfa658fb
5 changed files with 22 additions and 23 deletions

View file

@ -8,7 +8,6 @@ import (
"strings"
"github.com/github/gh-cli/internal/ghrepo"
"github.com/pkg/errors"
)
// Repository contains information about a GitHub repo
@ -82,7 +81,7 @@ func GitHubRepo(client *Client, repo ghrepo.Interface) (*Repository, error) {
if err != nil || result.Repository.ID == "" {
newErr := fmt.Errorf("failed to determine repository ID for '%s'", ghrepo.FullName(repo))
if err != nil {
newErr = errors.Wrap(err, newErr.Error())
newErr = fmt.Errorf("%s: %w", newErr, err)
}
return nil, newErr
}

View file

@ -1,6 +1,7 @@
package command
import (
"errors"
"fmt"
"io"
"net/url"
@ -14,7 +15,6 @@ import (
"github.com/github/gh-cli/internal/ghrepo"
"github.com/github/gh-cli/pkg/githubtemplate"
"github.com/github/gh-cli/utils"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)
@ -314,11 +314,11 @@ func issueCreate(cmd *cobra.Command, args []string) error {
title, err := cmd.Flags().GetString("title")
if err != nil {
return errors.Wrap(err, "could not parse title")
return fmt.Errorf("could not parse title: %w", err)
}
body, err := cmd.Flags().GetString("body")
if err != nil {
return errors.Wrap(err, "could not parse body")
return fmt.Errorf("could not parse body: %w", err)
}
interactive := title == "" || body == ""
@ -326,7 +326,7 @@ func issueCreate(cmd *cobra.Command, args []string) error {
if interactive {
tb, err := titleBodySurvey(cmd, title, body, templateFiles)
if err != nil {
return errors.Wrap(err, "could not collect title and/or body")
return fmt.Errorf("could not collect title and/or body: %w", err)
}
action = tb.Action

View file

@ -1,6 +1,7 @@
package command
import (
"errors"
"fmt"
"net/url"
"sort"
@ -12,7 +13,6 @@ import (
"github.com/github/gh-cli/internal/ghrepo"
"github.com/github/gh-cli/pkg/githubtemplate"
"github.com/github/gh-cli/utils"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)
@ -25,7 +25,7 @@ func prCreate(cmd *cobra.Command, _ []string) error {
client, err := apiClientForContext(ctx)
if err != nil {
return errors.Wrap(err, "could not initialize API client")
return fmt.Errorf("could not initialize API client: %w", err)
}
baseRepoOverride, _ := cmd.Flags().GetString("repo")
@ -36,12 +36,12 @@ func prCreate(cmd *cobra.Command, _ []string) error {
baseRepo, err := repoContext.BaseRepo()
if err != nil {
return errors.Wrap(err, "could not determine the base repository")
return fmt.Errorf("could not determine base repository: %w", err)
}
headBranch, err := ctx.Branch()
if err != nil {
return errors.Wrap(err, "could not determine the current branch")
return fmt.Errorf("could not determine the current branch: %w", err)
}
baseBranch, err := cmd.Flags().GetString("base")
@ -86,7 +86,7 @@ func prCreate(cmd *cobra.Command, _ []string) error {
if headRemote == nil {
headRemote, err = repoContext.RemoteForRepo(headRepo)
if err != nil {
return errors.Wrap(err, "git remote not found for head repository")
return fmt.Errorf("git remote not found for head repository: %w", err)
}
}
@ -111,7 +111,7 @@ func prCreate(cmd *cobra.Command, _ []string) error {
isWeb, err := cmd.Flags().GetBool("web")
if err != nil {
return errors.Wrap(err, "could not parse web")
return fmt.Errorf("could not parse web: %q", err)
}
if isWeb {
openURL := fmt.Sprintf(`https://github.com/%s/pull/%s`, ghrepo.FullName(headRepo), headBranch)
@ -130,11 +130,11 @@ func prCreate(cmd *cobra.Command, _ []string) error {
title, err := cmd.Flags().GetString("title")
if err != nil {
return errors.Wrap(err, "could not parse title")
return fmt.Errorf("could not parse title: %w", err)
}
body, err := cmd.Flags().GetString("body")
if err != nil {
return errors.Wrap(err, "could not parse body")
return fmt.Errorf("could not parse body: %w", err)
}
action := SubmitAction
@ -150,7 +150,7 @@ func prCreate(cmd *cobra.Command, _ []string) error {
tb, err := titleBodySurvey(cmd, title, body, templateFiles)
if err != nil {
return errors.Wrap(err, "could not collect title and/or body")
return fmt.Errorf("could not collect title and/or body: %w", err)
}
action = tb.Action
@ -170,7 +170,7 @@ func prCreate(cmd *cobra.Command, _ []string) error {
isDraft, err := cmd.Flags().GetBool("draft")
if err != nil {
return errors.Wrap(err, "could not parse draft")
return fmt.Errorf("could not parse draft: %w", err)
}
if action == SubmitAction {
@ -184,7 +184,7 @@ func prCreate(cmd *cobra.Command, _ []string) error {
pr, err := api.CreatePullRequest(client, baseRepo, params)
if err != nil {
return errors.Wrap(err, "failed to create pull request")
return fmt.Errorf("failed to create pull request: %w", err)
}
fmt.Fprintln(cmd.OutOrStdout(), pr.URL)

View file

@ -1,10 +1,11 @@
package command
import (
"fmt"
"github.com/AlecAivazis/survey/v2"
"github.com/github/gh-cli/pkg/githubtemplate"
"github.com/github/gh-cli/pkg/surveyext"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)
@ -42,7 +43,7 @@ func confirm() (Action, error) {
err := survey.Ask(confirmQs, &confirmAnswers)
if err != nil {
return -1, errors.Wrap(err, "could not prompt")
return -1, fmt.Errorf("could not prompt: %w", err)
}
return Action(confirmAnswers.Confirmation), nil
@ -68,7 +69,7 @@ func selectTemplate(templatePaths []string) (string, error) {
},
}
if err := survey.Ask(selectQs, &templateResponse); err != nil {
return "", errors.Wrap(err, "could not prompt")
return "", fmt.Errorf("could not prompt: %w", err)
}
}
@ -117,12 +118,12 @@ func titleBodySurvey(cmd *cobra.Command, providedTitle string, providedBody stri
err := survey.Ask(qs, &inProgress)
if err != nil {
return nil, errors.Wrap(err, "could not prompt")
return nil, fmt.Errorf("could not prompt: %w", err)
}
confirmA, err := confirm()
if err != nil {
return nil, errors.Wrap(err, "unable to confirm")
return nil, fmt.Errorf("unable to confirm: %w", err)
}
inProgress.Action = confirmA

1
go.mod
View file

@ -11,7 +11,6 @@ require (
github.com/mattn/go-isatty v0.0.9
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b
github.com/mitchellh/go-homedir v1.1.0
github.com/pkg/errors v0.8.1
github.com/spf13/cobra v0.0.5
github.com/spf13/pflag v1.0.5
github.com/vilmibm/go-termd v0.0.4