Skip to content

Commit 19554a5

Browse files
committed
Replace usage of github.com/pkg/errors with stdlib
1 parent b8013bf commit 19554a5

File tree

15 files changed

+58
-107
lines changed

15 files changed

+58
-107
lines changed

api/approval.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ package api
1919
import (
2020
"bufio"
2121
"bytes"
22+
"fmt"
2223
"io"
2324

2425
"github.com/go-playground/validator/v10"
25-
"github.com/pkg/errors"
2626

2727
"k8s.io/enhancements/pkg/yaml"
2828
)
@@ -51,7 +51,7 @@ type PRRApproval struct {
5151
func (prr *PRRApproval) Validate() error {
5252
v := validator.New()
5353
if err := v.Struct(prr); err != nil {
54-
return errors.Wrap(err, "running validation")
54+
return fmt.Errorf("running validation: %w", err)
5555
}
5656

5757
return nil
@@ -128,17 +128,17 @@ func (p *PRRHandler) Parse(in io.Reader) (*PRRApproval, error) {
128128

129129
approval := &PRRApproval{}
130130
if err := scanner.Err(); err != nil {
131-
return approval, errors.Wrap(err, "reading file")
131+
return approval, fmt.Errorf("reading file: %w", err)
132132
}
133133

134134
if err := yaml.UnmarshalStrict(body.Bytes(), &approval); err != nil {
135-
p.Errors = append(p.Errors, errors.Wrap(err, "error unmarshalling YAML"))
136-
return approval, errors.Wrap(err, "unmarshalling YAML")
135+
p.Errors = append(p.Errors, fmt.Errorf("error unmarshalling YAML: %w", err))
136+
return approval, fmt.Errorf("unmarshalling YAML: %w", err)
137137
}
138138

139139
if valErr := approval.Validate(); valErr != nil {
140-
p.Errors = append(p.Errors, errors.Wrap(valErr, "validating PRR"))
141-
return approval, errors.Wrap(valErr, "validating PRR")
140+
p.Errors = append(p.Errors, fmt.Errorf("validating PRR: %w", valErr))
141+
return approval, fmt.Errorf("validating PRR: %w", valErr)
142142
}
143143

144144
return approval, nil

api/error.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ limitations under the License.
1717
package api
1818

1919
import (
20-
"github.com/pkg/errors"
20+
"errors"
2121
)
2222

2323
var (

api/groups.go

+8-19
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,13 @@ package api
1818

1919
import (
2020
"bufio"
21+
"errors"
2122
"fmt"
2223
"io/ioutil"
2324
"net/http"
2425
"regexp"
2526
"sort"
2627

27-
"github.com/pkg/errors"
28-
2928
"k8s.io/enhancements/pkg/yaml"
3029
)
3130

@@ -92,18 +91,13 @@ var _ GroupFetcher = &RemoteGroupFetcher{}
9291
func (f *RemoteGroupFetcher) FetchGroups() ([]string, error) {
9392
resp, err := http.Get(f.GroupsListURL)
9493
if err != nil {
95-
return nil, errors.Wrap(err, "fetching SIG list")
94+
return nil, fmt.Errorf("fetching SIG list: %w", err)
9695
}
9796

9897
defer resp.Body.Close()
9998

10099
if resp.StatusCode != http.StatusOK {
101-
return nil, errors.New(
102-
fmt.Sprintf(
103-
"invalid status code when fetching SIG list: %d",
104-
resp.StatusCode,
105-
),
106-
)
100+
return nil, fmt.Errorf("invalid status code when fetching SIG list: %d", resp.StatusCode)
107101
}
108102

109103
re := regexp.MustCompile(`- dir: (.*)$`)
@@ -118,7 +112,7 @@ func (f *RemoteGroupFetcher) FetchGroups() ([]string, error) {
118112
}
119113

120114
if err := scanner.Err(); err != nil {
121-
return nil, errors.Wrap(err, "scanning SIG list")
115+
return nil, fmt.Errorf("scanning SIG list: %w", err)
122116
}
123117

124118
sort.Strings(result)
@@ -130,31 +124,26 @@ func (f *RemoteGroupFetcher) FetchGroups() ([]string, error) {
130124
func (f *RemoteGroupFetcher) FetchPRRApprovers() ([]string, error) {
131125
resp, err := http.Get(f.OwnersAliasesURL)
132126
if err != nil {
133-
return nil, errors.Wrap(err, "fetching owners aliases")
127+
return nil, fmt.Errorf("fetching owners aliases: %w", err)
134128
}
135129

136130
defer resp.Body.Close()
137131

138132
if resp.StatusCode != http.StatusOK {
139-
return nil, errors.New(
140-
fmt.Sprintf(
141-
"invalid status code when fetching owners aliases: %d",
142-
resp.StatusCode,
143-
),
144-
)
133+
return nil, fmt.Errorf("invalid status code when fetching owners aliases: %d", resp.StatusCode)
145134
}
146135

147136
body, err := ioutil.ReadAll(resp.Body)
148137
if err != nil {
149-
return nil, errors.Wrap(err, "reading owners aliases")
138+
return nil, fmt.Errorf("reading owners aliases: %w", err)
150139
}
151140

152141
config := &struct {
153142
Data map[string][]string `json:"aliases,omitempty" yaml:"aliases,omitempty"`
154143
}{}
155144

156145
if err := yaml.UnmarshalStrict(body, config); err != nil {
157-
return nil, errors.Wrap(err, "unmarshalling owners aliases")
146+
return nil, fmt.Errorf("unmarshalling owners aliases: %w", err)
158147
}
159148

160149
var result []string

api/proposal.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
"strings"
2626

2727
"github.com/go-playground/validator/v10"
28-
"github.com/pkg/errors"
2928

3029
"k8s.io/enhancements/pkg/yaml"
3130
)
@@ -177,7 +176,7 @@ func (k *KEPHandler) Parse(in io.Reader) (*Proposal, error) {
177176
}
178177

179178
if err := scanner.Err(); err != nil {
180-
return kep, errors.Wrap(err, "reading file")
179+
return kep, fmt.Errorf("reading file: %w", err)
181180
}
182181

183182
// this file is just the KEP metadata
@@ -187,8 +186,8 @@ func (k *KEPHandler) Parse(in io.Reader) (*Proposal, error) {
187186
}
188187

189188
if err := yaml.UnmarshalStrict(metadata, &kep); err != nil {
190-
k.Errors = append(k.Errors, errors.Wrap(err, "error unmarshalling YAML"))
191-
return kep, errors.Wrap(err, "unmarshalling YAML")
189+
k.Errors = append(k.Errors, fmt.Errorf("error unmarshalling YAML: %w", err))
190+
return kep, fmt.Errorf("unmarshalling YAML: %w", err)
192191
}
193192

194193
if err := k.validateStruct(kep); err != nil {

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ require (
88
github.com/google/go-github/v33 v33.0.0
99
github.com/maxbrunsfeld/counterfeiter/v6 v6.3.0
1010
github.com/olekukonko/tablewriter v0.0.5
11-
github.com/pkg/errors v0.9.1
1211
github.com/psampaz/go-mod-outdated v0.8.0
1312
github.com/sirupsen/logrus v1.7.0
1413
github.com/spf13/cobra v1.1.1
@@ -44,6 +43,7 @@ require (
4443
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
4544
github.com/mitchellh/go-homedir v1.1.0 // indirect
4645
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
46+
github.com/pkg/errors v0.9.1 // indirect
4747
github.com/pmezard/go-difflib v1.0.0 // indirect
4848
github.com/prometheus/client_golang v1.6.0 // indirect
4949
github.com/prometheus/client_model v0.2.0 // indirect

keps/sig-scheduling/624-scheduling-framework/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ func NewServiceAffinity(args *runtime.Unknown, h FrameworkHandle) (Plugin, error
588588
LabelName, LabelValue string
589589
}
590590
if err := json.Unmarshal(args.Raw, &config); err != nil {
591-
return nil, errors.Wrap(err, "could not parse args")
591+
return nil, fmt.Errorf("could not parse args: %w", err)
592592
}
593593
//...
594594
}

pkg/kepctl/commands/create.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ limitations under the License.
1717
package commands
1818

1919
import (
20-
"github.com/pkg/errors"
20+
"fmt"
21+
2122
"github.com/spf13/cobra"
2223

2324
"k8s.io/enhancements/api"
@@ -128,7 +129,7 @@ func addCreate(topLevel *cobra.Command) {
128129
func runCreate(opts *proposal.CreateOpts) error {
129130
rc, err := repo.New(rootOpts.RepoPath)
130131
if err != nil {
131-
return errors.Wrap(err, "creating repo client")
132+
return fmt.Errorf("creating repo client: %w", err)
132133
}
133134

134135
opts.Repo = rc

pkg/kepctl/commands/promote.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ limitations under the License.
1717
package commands
1818

1919
import (
20-
"github.com/pkg/errors"
20+
"fmt"
21+
2122
"github.com/spf13/cobra"
2223

2324
"k8s.io/enhancements/pkg/proposal"
@@ -65,7 +66,7 @@ func addPromote(topLevel *cobra.Command) {
6566
func runPromote(opts *proposal.PromoteOpts) error {
6667
rc, err := repo.New(rootOpts.RepoPath)
6768
if err != nil {
68-
return errors.Wrap(err, "creating repo client")
69+
return fmt.Errorf("creating repo client: %w", err)
6970
}
7071

7172
opts.Repo = rc

pkg/kepctl/commands/query.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"fmt"
2121
"os"
2222

23-
"github.com/pkg/errors"
2423
"github.com/spf13/cobra"
2524

2625
"k8s.io/enhancements/pkg/output"
@@ -115,7 +114,7 @@ func addQuery(topLevel *cobra.Command) {
115114
func runQuery(opts *repo.QueryOpts) error {
116115
rc, err := repo.New(rootOpts.RepoPath)
117116
if err != nil {
118-
return errors.Wrap(err, "creating repo client")
117+
return fmt.Errorf("creating repo client: %w", err)
119118
}
120119
rc.TokenPath = rootOpts.TokenPath
121120

pkg/kepval/approval.go

+9-15
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ limitations under the License.
1717
package kepval
1818

1919
import (
20+
"errors"
2021
"fmt"
2122
"os"
2223
"path/filepath"
2324
"strings"
2425

2526
"github.com/blang/semver/v4"
26-
"github.com/pkg/errors"
2727
"github.com/sirupsen/logrus"
2828

2929
"k8s.io/enhancements/api"
@@ -32,7 +32,7 @@ import (
3232
func ValidatePRR(kep *api.Proposal, h *api.PRRHandler, prrDir string) error {
3333
requiredPRRApproval, err := isPRRRequired(kep)
3434
if err != nil {
35-
return errors.Wrap(err, "checking if PRR is required")
35+
return fmt.Errorf("checking if PRR is required: %w", err)
3636
}
3737

3838
if !requiredPRRApproval {
@@ -55,24 +55,24 @@ func ValidatePRR(kep *api.Proposal, h *api.PRRHandler, prrDir string) error {
5555
}
5656

5757
if err != nil {
58-
return errors.Wrapf(err, "could not open file %s", prrFilepath)
58+
return fmt.Errorf("could not open file %s: %w", prrFilepath, err)
5959
}
6060

6161
// TODO: Create a context to hold the parsers
6262
prr, prrParseErr := h.Parse(prrFile)
6363
if prrParseErr != nil {
64-
return errors.Wrap(prrParseErr, "parsing PRR approval file")
64+
return fmt.Errorf("parsing PRR approval file: %w", prrParseErr)
6565
}
6666

6767
// TODO: This shouldn't be required once we push the errors into the
6868
// parser struct
6969
if prr.Error != nil {
70-
return errors.Wrapf(prr.Error, "%v has an error", prrFilepath)
70+
return fmt.Errorf("%v has an error: %w", prrFilepath, prr.Error)
7171
}
7272

7373
stagePRRApprover, err := prr.ApproverForStage(kep.Stage)
7474
if err != nil {
75-
return errors.Wrapf(err, "getting PRR approver for %s stage", kep.Stage)
75+
return fmt.Errorf("getting PRR approver for %s stage: %w", kep.Stage, err)
7676
}
7777

7878
if stagePRRApprover == "" {
@@ -85,13 +85,7 @@ func ValidatePRR(kep *api.Proposal, h *api.PRRHandler, prrDir string) error {
8585

8686
validApprover := api.IsOneOf(stagePRRApprover, h.PRRApprovers)
8787
if !validApprover {
88-
return errors.New(
89-
fmt.Sprintf(
90-
"this contributor (%s) is not a PRR approver (%v)",
91-
stagePRRApprover,
92-
h.PRRApprovers,
93-
),
94-
)
88+
return fmt.Errorf("this contributor (%s) is not a PRR approver (%v)", stagePRRApprover, h.PRRApprovers)
9589
}
9690

9791
return nil
@@ -116,12 +110,12 @@ func isPRRRequired(kep *api.Proposal) (required bool, err error) {
116110
// TODO: Consider making this a function
117111
prrRequiredAtSemVer, err := semver.ParseTolerant("v1.21")
118112
if err != nil {
119-
return required, errors.Wrap(err, "creating a SemVer object for PRRs")
113+
return required, fmt.Errorf("creating a SemVer object for PRRs: %w", err)
120114
}
121115

122116
latestSemVer, err := semver.ParseTolerant(kep.LatestMilestone)
123117
if err != nil {
124-
return required, errors.Wrap(err, "creating a SemVer object for latest milestone")
118+
return required, fmt.Errorf("creating a SemVer object for latest milestone: %w", err)
125119
}
126120

127121
if latestSemVer.LT(prrRequiredAtSemVer) {

pkg/proposal/create.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
"strings"
2525
"time"
2626

27-
"github.com/pkg/errors"
2827
"github.com/sirupsen/logrus"
2928

3029
"k8s.io/enhancements/api"
@@ -115,7 +114,7 @@ func createKEP(kep *api.Proposal, opts *CreateOpts) error {
115114
)
116115

117116
if writeErr := ioutil.WriteFile(newPath, template, os.ModePerm); writeErr != nil {
118-
return errors.Wrapf(writeErr, "writing KEP data to file")
117+
return fmt.Errorf("writing KEP data to file: %w", writeErr)
119118
}
120119

121120
return nil

pkg/proposal/options.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@ limitations under the License.
1717
package proposal
1818

1919
import (
20+
"errors"
2021
"fmt"
2122
"regexp"
22-
23-
"github.com/pkg/errors"
2423
)
2524

2625
type Options struct {

pkg/repo/query.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ limitations under the License.
1717
package repo
1818

1919
import (
20+
"errors"
2021
"fmt"
2122
"regexp"
2223

23-
"github.com/pkg/errors"
2424
"github.com/sirupsen/logrus"
2525

2626
"k8s.io/enhancements/api"
@@ -95,7 +95,7 @@ func (r *Repo) Query(opts *QueryOpts) ([]*api.Proposal, error) {
9595
if r.TokenPath != "" {
9696
logrus.Infof("Setting GitHub token: %v", r.TokenPath)
9797
if tokenErr := r.SetGitHubToken(r.TokenPath); tokenErr != nil {
98-
return nil, errors.Wrapf(tokenErr, "setting GitHub token")
98+
return nil, fmt.Errorf("setting GitHub token: %w", tokenErr)
9999
}
100100
}
101101

@@ -105,7 +105,7 @@ func (r *Repo) Query(opts *QueryOpts) ([]*api.Proposal, error) {
105105
// KEPs in the local filesystem
106106
localKEPs, err := r.LoadLocalKEPs(sig)
107107
if err != nil {
108-
return nil, errors.Wrap(err, "loading local KEPs")
108+
return nil, fmt.Errorf("loading local KEPs: %w", err)
109109
}
110110

111111
allKEPs = append(allKEPs, localKEPs...)

0 commit comments

Comments
 (0)