Skip to content

Commit 153d645

Browse files
remove pkg/errors
1 parent a2cecb4 commit 153d645

File tree

5 files changed

+27
-32
lines changed

5 files changed

+27
-32
lines changed

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ go 1.23.0
55
require (
66
github.com/PuerkitoBio/goquery v1.8.1
77
github.com/google/go-github/v52 v52.0.0
8-
github.com/pkg/errors v0.9.1
98
github.com/urfave/cli/v2 v2.25.1
109
golang.org/x/mod v0.24.0
1110
golang.org/x/oauth2 v0.7.0

go.sum

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,11 @@ github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiu
1818
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
1919
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
2020
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
21+
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
2122
github.com/google/go-github/v52 v52.0.0 h1:uyGWOY+jMQ8GVGSX8dkSwCzlehU3WfdxQ7GweO/JP7M=
2223
github.com/google/go-github/v52 v52.0.0/go.mod h1:WJV6VEEUPuMo5pXqqa2ZCZEdbQqua4zAk2MZTIo+m+4=
2324
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
2425
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
25-
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
26-
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
2726
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
2827
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
2928
github.com/urfave/cli/v2 v2.25.1 h1:zw8dSP7ghX0Gmm8vugrs6q9Ku0wzweqPyshy+syu9Gw=
@@ -38,8 +37,6 @@ golang.org/x/crypto v0.13.0 h1:mvySKfSWJ+UKUii46M40LOvyWfN0s2U+46/jDd0e6Ck=
3837
golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc=
3938
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
4039
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
41-
golang.org/x/mod v0.13.0 h1:I/DsJXRlw/8l/0c24sM9yb0T4z9liZTduXvdAWYiysY=
42-
golang.org/x/mod v0.13.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
4340
golang.org/x/mod v0.24.0 h1:ZfthKaKaT4NrhGVZHO1/WDTwGES4De8KtWO0SIbNJMU=
4441
golang.org/x/mod v0.24.0/go.mod h1:IXM97Txy2VM4PJ3gI61r1YEk/gAj6zAHN3AdZt6S9Ww=
4542
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
@@ -59,6 +56,7 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ
5956
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
6057
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
6158
golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E=
59+
golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
6260
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
6361
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
6462
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=

major/major.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"strconv"
1212
"strings"
1313

14-
"github.com/pkg/errors"
1514
"golang.org/x/mod/modfile"
1615
"golang.org/x/tools/go/ast/astutil"
1716
"golang.org/x/tools/go/packages"
@@ -27,7 +26,7 @@ func Run(dir, op, modName string, tag int) error {
2726
var modFile *modfile.File
2827
modFile, err := mod.GetModFile(dir)
2928
if err != nil {
30-
return errors.Wrap(err, "could not get go.mod file")
29+
return fmt.Errorf("could not get go.mod file: %w", err)
3130
}
3231
if modName == "" {
3332
client = false
@@ -44,7 +43,7 @@ func Run(dir, op, modName string, tag int) error {
4443
c := &packages.Config{Mode: packages.NeedName | packages.NeedFiles, Tests: true, Dir: dir}
4544
pkgs, err := packages.Load(c, "./...")
4645
if err != nil {
47-
return errors.Wrap(err, "could not load package")
46+
return fmt.Errorf("could not load package: %w", err)
4847
}
4948
ids := map[string]struct{}{}
5049
files := map[string]struct{}{}
@@ -86,11 +85,11 @@ func Run(dir, op, modName string, tag int) error {
8685
}
8786
bts, err := modFile.Format()
8887
if err != nil {
89-
return errors.Wrap(err, "could not format go.mod file with new import path")
88+
return fmt.Errorf("could not format go.mod file with new import path: %w", err)
9089
}
9190
err = os.WriteFile(filepath.Join(dir, "go.mod"), bts, 0660)
9291
if err != nil {
93-
return errors.Wrap(err, "could not rewrite go.mod file")
92+
return fmt.Errorf("could not rewrite go.mod file: %w", err)
9493
}
9594
if client {
9695
fmt.Println("running go mod tidy...")
@@ -172,7 +171,7 @@ func updateImportPath(p *packages.Package, old, new, sep string, files map[strin
172171
fset := token.NewFileSet()
173172
parsed, err := parser.ParseFile(fset, goFileName, nil, parser.ParseComments)
174173
if err != nil {
175-
return errors.Wrapf(err, "could not parse go file %v", goFileName)
174+
return fmt.Errorf("could not parse go file %v: %w", goFileName, err)
176175
}
177176

178177
var rewritten bool
@@ -192,12 +191,12 @@ func updateImportPath(p *packages.Package, old, new, sep string, files map[strin
192191

193192
f, err := os.Create(goFileName)
194193
if err != nil {
195-
return errors.Wrapf(err, "could not create go file %v", goFileName)
194+
return fmt.Errorf("could not create go file %v: %w", goFileName, err)
196195
}
197196
err = format.Node(f, fset, parsed)
198197
f.Close()
199198
if err != nil {
200-
return errors.Wrapf(err, "could not rewrite go file %v", goFileName)
199+
return fmt.Errorf("could not rewrite go file %v: %w", goFileName, err)
201200
}
202201
}
203202

migrate/migrate.go

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616

1717
"github.com/PuerkitoBio/goquery"
1818
"github.com/google/go-github/v52/github"
19-
"github.com/pkg/errors"
2019
"golang.org/x/mod/modfile"
2120
"golang.org/x/mod/semver"
2221
"golang.org/x/oauth2"
@@ -31,7 +30,7 @@ import (
3130
func Run(githubToken string, limit int, test bool) error {
3231
f, err := mod.GetModFile(".")
3332
if err != nil {
34-
return errors.Wrap(err, "could not get mod file")
33+
return fmt.Errorf("could not get mod file: %w", err)
3534
}
3635
ts := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: githubToken})
3736
tc := oauth2.NewClient(oauth2.NoContext, ts)
@@ -77,34 +76,34 @@ func migrate(path string, gc *github.Client, test bool) error {
7776
fmt.Printf("git clone %v\n", path)
7877
tempdir, err := os.MkdirTemp("", strings.Replace(path, "/", "_", -1))
7978
if err != nil {
80-
return errors.Wrap(err, "tempdir err")
79+
return fmt.Errorf("tempdir err: %w", err)
8180
}
8281
defer os.RemoveAll(tempdir)
8382
red, err := deduceVanity(path)
8483
if err != nil {
85-
return errors.Wrap(err, "error deducing vanity")
84+
return fmt.Errorf("error deducing vanity: %w", err)
8685
}
8786
dir, err := gitclone(red.gitURL, tempdir)
8887
if err != nil {
89-
return errors.Wrap(err, "error running git clone")
88+
return fmt.Errorf("error running git clone: %w", err)
9089
}
9190
if checkMod(dir) {
9291
fmt.Printf("%v already migrated to modules\n", path)
9392
return nil
9493
}
9594
err = modinit(dir, path)
9695
if err != nil {
97-
return errors.Wrap(err, "err running go mod init")
96+
return fmt.Errorf("err running go mod init: %w", err)
9897
}
9998
fmt.Printf("downloading dependencies for %v\n", path)
10099
err = getdeps(dir)
101100
if err != nil {
102-
return errors.Wrap(err, "err running go get ./...")
101+
return fmt.Errorf("err running go get ./...: %w", err)
103102
}
104103
t := getTag(dir)
105104
fmt.Printf("upgrading %v to v%v\n", path, t)
106105
if err := major.Run(dir, "upgrade", "", t); err != nil {
107-
return errors.Wrap(err, "err upgrading import paths")
106+
return fmt.Errorf("err upgrading import paths: %w", err)
108107
}
109108

110109
err = rewriteGitIgnore(dir)
@@ -121,33 +120,33 @@ func migrate(path string, gc *github.Client, test bool) error {
121120
owner, repo := ss[1], ss[2]
122121
r, _, err := gc.Repositories.CreateFork(context.Background(), owner, repo, &github.RepositoryCreateForkOptions{})
123122
if _, ok := err.(*github.AcceptedError); !ok {
124-
return errors.Wrap(err, "error creating a fork")
123+
return fmt.Errorf("error creating a fork: %w", err)
125124
}
126125
time.Sleep(time.Second * 2)
127126
remote := r.GetCloneURL()
128127
err = addRemote(dir, remote)
129128
if err != nil {
130-
return errors.Wrap(err, "error adding remote")
129+
return fmt.Errorf("error adding remote: %w", err)
131130
}
132131

133132
err = checkout(dir)
134133
if err != nil {
135-
return errors.Wrap(err, "error checking out new branch")
134+
return fmt.Errorf("error checking out new branch: %w", err)
136135
}
137136

138137
err = add(dir)
139138
if err != nil {
140-
errors.Wrap(err, "error tracking files")
139+
return fmt.Errorf("error tracking files: %w", err)
141140
}
142141

143142
err = commit(dir)
144143
if err != nil {
145-
errors.Wrap(err, "error committing changes")
144+
return fmt.Errorf("error committing changes: %w", err)
146145
}
147146

148147
err = push(dir)
149148
if err != nil {
150-
errors.Wrap(err, "error pushing to github")
149+
return fmt.Errorf("error pushing to github: %w", err)
151150
}
152151

153152
if test {
@@ -344,7 +343,7 @@ func rewriteGitIgnore(dir string) error {
344343
return nil
345344
}
346345
if err != nil {
347-
return errors.Wrap(err, "could not open gitignore")
346+
return fmt.Errorf("could not open gitignore: %w", err)
348347
}
349348
lines := []string{}
350349
scnr := bufio.NewScanner(f)
@@ -356,7 +355,7 @@ func rewriteGitIgnore(dir string) error {
356355
}
357356
if scnr.Err() != nil {
358357
f.Close()
359-
return errors.Wrap(err, "error while scanning")
358+
return fmt.Errorf("error while scanning: %w", err)
360359
}
361360
f.Close()
362361
return os.WriteFile(p, []byte(strings.Join(lines, "\n")+"\n"), 0o666)

mod.go

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

33
import (
4+
"fmt"
45
"os"
56
"path/filepath"
67

7-
"github.com/pkg/errors"
88
"golang.org/x/mod/modfile"
99
)
1010

@@ -13,11 +13,11 @@ import (
1313
func GetModFile(dir string) (*modfile.File, error) {
1414
bts, err := os.ReadFile(filepath.Join(dir, "go.mod"))
1515
if err != nil {
16-
return nil, errors.Wrap(err, "could not open go.mod file")
16+
return nil, fmt.Errorf("could not open go.mod file: %w", err)
1717
}
1818
f, err := modfile.Parse(filepath.Join(dir, "go.mod"), bts, nil)
1919
if err != nil {
20-
return nil, errors.Wrap(err, "could not parse go.mod file")
20+
return nil, fmt.Errorf("could not parse go.mod file: %w", err)
2121
}
2222
return f, nil
2323
}

0 commit comments

Comments
 (0)