diff --git a/api/queries_repo.go b/api/queries_repo.go index 27cd3d6b0..46b0fa96a 100644 --- a/api/queries_repo.go +++ b/api/queries_repo.go @@ -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 } diff --git a/command/issue.go b/command/issue.go index 452cf0673..fea96ace6 100644 --- a/command/issue.go +++ b/command/issue.go @@ -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 diff --git a/command/pr_create.go b/command/pr_create.go index bacc74479..45dabd10c 100644 --- a/command/pr_create.go +++ b/command/pr_create.go @@ -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) diff --git a/command/title_body_survey.go b/command/title_body_survey.go index 2b11c326f..914d03c0b 100644 --- a/command/title_body_survey.go +++ b/command/title_body_survey.go @@ -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 diff --git a/go.mod b/go.mod index df49a1664..f0cf8445a 100644 --- a/go.mod +++ b/go.mod @@ -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