Skip to content

Commit 11bfa65

Browse files
author
Nate Smith
authored
Merge pull request cli#250 from github/no-errors-wrap
Migrate away from `errors.Wrap()`
2 parents a0f2e17 + b44dad2 commit 11bfa65

5 files changed

Lines changed: 22 additions & 23 deletions

File tree

api/queries_repo.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"strings"
99

1010
"github.com/github/gh-cli/internal/ghrepo"
11-
"github.com/pkg/errors"
1211
)
1312

1413
// Repository contains information about a GitHub repo
@@ -82,7 +81,7 @@ func GitHubRepo(client *Client, repo ghrepo.Interface) (*Repository, error) {
8281
if err != nil || result.Repository.ID == "" {
8382
newErr := fmt.Errorf("failed to determine repository ID for '%s'", ghrepo.FullName(repo))
8483
if err != nil {
85-
newErr = errors.Wrap(err, newErr.Error())
84+
newErr = fmt.Errorf("%s: %w", newErr, err)
8685
}
8786
return nil, newErr
8887
}

command/issue.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package command
22

33
import (
4+
"errors"
45
"fmt"
56
"io"
67
"net/url"
@@ -14,7 +15,6 @@ import (
1415
"github.com/github/gh-cli/internal/ghrepo"
1516
"github.com/github/gh-cli/pkg/githubtemplate"
1617
"github.com/github/gh-cli/utils"
17-
"github.com/pkg/errors"
1818
"github.com/spf13/cobra"
1919
"github.com/spf13/pflag"
2020
)
@@ -314,19 +314,19 @@ func issueCreate(cmd *cobra.Command, args []string) error {
314314

315315
title, err := cmd.Flags().GetString("title")
316316
if err != nil {
317-
return errors.Wrap(err, "could not parse title")
317+
return fmt.Errorf("could not parse title: %w", err)
318318
}
319319
body, err := cmd.Flags().GetString("body")
320320
if err != nil {
321-
return errors.Wrap(err, "could not parse body")
321+
return fmt.Errorf("could not parse body: %w", err)
322322
}
323323

324324
interactive := title == "" || body == ""
325325

326326
if interactive {
327327
tb, err := titleBodySurvey(cmd, title, body, templateFiles)
328328
if err != nil {
329-
return errors.Wrap(err, "could not collect title and/or body")
329+
return fmt.Errorf("could not collect title and/or body: %w", err)
330330
}
331331

332332
action = tb.Action

command/pr_create.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package command
22

33
import (
4+
"errors"
45
"fmt"
56
"net/url"
67
"sort"
@@ -12,7 +13,6 @@ import (
1213
"github.com/github/gh-cli/internal/ghrepo"
1314
"github.com/github/gh-cli/pkg/githubtemplate"
1415
"github.com/github/gh-cli/utils"
15-
"github.com/pkg/errors"
1616
"github.com/spf13/cobra"
1717
)
1818

@@ -25,7 +25,7 @@ func prCreate(cmd *cobra.Command, _ []string) error {
2525

2626
client, err := apiClientForContext(ctx)
2727
if err != nil {
28-
return errors.Wrap(err, "could not initialize API client")
28+
return fmt.Errorf("could not initialize API client: %w", err)
2929
}
3030

3131
baseRepoOverride, _ := cmd.Flags().GetString("repo")
@@ -36,12 +36,12 @@ func prCreate(cmd *cobra.Command, _ []string) error {
3636

3737
baseRepo, err := repoContext.BaseRepo()
3838
if err != nil {
39-
return errors.Wrap(err, "could not determine the base repository")
39+
return fmt.Errorf("could not determine base repository: %w", err)
4040
}
4141

4242
headBranch, err := ctx.Branch()
4343
if err != nil {
44-
return errors.Wrap(err, "could not determine the current branch")
44+
return fmt.Errorf("could not determine the current branch: %w", err)
4545
}
4646

4747
baseBranch, err := cmd.Flags().GetString("base")
@@ -86,7 +86,7 @@ func prCreate(cmd *cobra.Command, _ []string) error {
8686
if headRemote == nil {
8787
headRemote, err = repoContext.RemoteForRepo(headRepo)
8888
if err != nil {
89-
return errors.Wrap(err, "git remote not found for head repository")
89+
return fmt.Errorf("git remote not found for head repository: %w", err)
9090
}
9191
}
9292

@@ -111,7 +111,7 @@ func prCreate(cmd *cobra.Command, _ []string) error {
111111

112112
isWeb, err := cmd.Flags().GetBool("web")
113113
if err != nil {
114-
return errors.Wrap(err, "could not parse web")
114+
return fmt.Errorf("could not parse web: %q", err)
115115
}
116116
if isWeb {
117117
openURL := fmt.Sprintf(`https://github.com/%s/pull/%s`, ghrepo.FullName(headRepo), headBranch)
@@ -130,11 +130,11 @@ func prCreate(cmd *cobra.Command, _ []string) error {
130130

131131
title, err := cmd.Flags().GetString("title")
132132
if err != nil {
133-
return errors.Wrap(err, "could not parse title")
133+
return fmt.Errorf("could not parse title: %w", err)
134134
}
135135
body, err := cmd.Flags().GetString("body")
136136
if err != nil {
137-
return errors.Wrap(err, "could not parse body")
137+
return fmt.Errorf("could not parse body: %w", err)
138138
}
139139

140140
action := SubmitAction
@@ -150,7 +150,7 @@ func prCreate(cmd *cobra.Command, _ []string) error {
150150

151151
tb, err := titleBodySurvey(cmd, title, body, templateFiles)
152152
if err != nil {
153-
return errors.Wrap(err, "could not collect title and/or body")
153+
return fmt.Errorf("could not collect title and/or body: %w", err)
154154
}
155155

156156
action = tb.Action
@@ -170,7 +170,7 @@ func prCreate(cmd *cobra.Command, _ []string) error {
170170

171171
isDraft, err := cmd.Flags().GetBool("draft")
172172
if err != nil {
173-
return errors.Wrap(err, "could not parse draft")
173+
return fmt.Errorf("could not parse draft: %w", err)
174174
}
175175

176176
if action == SubmitAction {
@@ -184,7 +184,7 @@ func prCreate(cmd *cobra.Command, _ []string) error {
184184

185185
pr, err := api.CreatePullRequest(client, baseRepo, params)
186186
if err != nil {
187-
return errors.Wrap(err, "failed to create pull request")
187+
return fmt.Errorf("failed to create pull request: %w", err)
188188
}
189189

190190
fmt.Fprintln(cmd.OutOrStdout(), pr.URL)

command/title_body_survey.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package command
22

33
import (
4+
"fmt"
5+
46
"github.com/AlecAivazis/survey/v2"
57
"github.com/github/gh-cli/pkg/githubtemplate"
68
"github.com/github/gh-cli/pkg/surveyext"
7-
"github.com/pkg/errors"
89
"github.com/spf13/cobra"
910
)
1011

@@ -42,7 +43,7 @@ func confirm() (Action, error) {
4243

4344
err := survey.Ask(confirmQs, &confirmAnswers)
4445
if err != nil {
45-
return -1, errors.Wrap(err, "could not prompt")
46+
return -1, fmt.Errorf("could not prompt: %w", err)
4647
}
4748

4849
return Action(confirmAnswers.Confirmation), nil
@@ -68,7 +69,7 @@ func selectTemplate(templatePaths []string) (string, error) {
6869
},
6970
}
7071
if err := survey.Ask(selectQs, &templateResponse); err != nil {
71-
return "", errors.Wrap(err, "could not prompt")
72+
return "", fmt.Errorf("could not prompt: %w", err)
7273
}
7374
}
7475

@@ -117,12 +118,12 @@ func titleBodySurvey(cmd *cobra.Command, providedTitle string, providedBody stri
117118

118119
err := survey.Ask(qs, &inProgress)
119120
if err != nil {
120-
return nil, errors.Wrap(err, "could not prompt")
121+
return nil, fmt.Errorf("could not prompt: %w", err)
121122
}
122123

123124
confirmA, err := confirm()
124125
if err != nil {
125-
return nil, errors.Wrap(err, "unable to confirm")
126+
return nil, fmt.Errorf("unable to confirm: %w", err)
126127
}
127128

128129
inProgress.Action = confirmA

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ require (
1111
github.com/mattn/go-isatty v0.0.9
1212
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b
1313
github.com/mitchellh/go-homedir v1.1.0
14-
github.com/pkg/errors v0.8.1
1514
github.com/spf13/cobra v0.0.5
1615
github.com/spf13/pflag v1.0.5
1716
github.com/vilmibm/go-termd v0.0.4

0 commit comments

Comments
 (0)