Skip to content

Commit

Permalink
deps: remove deprecated github.com/pkg/errors (#1125)
Browse files Browse the repository at this point in the history
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
Co-authored-by: Sajay Antony <sajaya@microsoft.com>
  • Loading branch information
mmorel-35 and sajayantony authored Sep 19, 2023
1 parent 3cffd9d commit d881fa8
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 22 deletions.
9 changes: 9 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ linters:
disable-all: true
enable:
- dupl
- errorlint
- gofmt
- goimports
- gomodguard
- gosimple
- govet
- ineffassign
Expand All @@ -19,5 +21,12 @@ linters:
linters-settings:
gofmt:
simplify: true
gomodguard:
blocked:
modules:
- github.com/pkg/errors:
recommendations:
- errors
- fmt
dupl:
threshold: 400
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ go 1.18

require (
github.com/opencontainers/go-digest v1.0.0
github.com/pkg/errors v0.9.1
github.com/russross/blackfriday v1.6.0
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415
github.com/xeipuuv/gojsonschema v1.2.0
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday v1.6.0 h1:KqfZb0pUVN2lYqZUYRddxF4OR8ZMURnJIG5Y3VRLtww=
Expand Down
4 changes: 3 additions & 1 deletion schema/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package schema
import (
"bufio"
"encoding/json"
"errors"
"io"
)

Expand All @@ -34,7 +35,8 @@ func (e *SyntaxError) Error() string { return e.msg }
// and converts it into a *schema.SyntaxError containing line/col information using the given reader.
// If the given error is not a *json.SyntaxError it is returned unchanged.
func WrapSyntaxError(r io.Reader, err error) error {
if serr, ok := err.(*json.SyntaxError); ok {
var serr *json.SyntaxError
if errors.As(err, &serr) {
buf := bufio.NewReader(r)
line := 0
col := 0
Expand Down
7 changes: 4 additions & 3 deletions schema/spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package schema_test

import (
"bytes"
"errors"
"fmt"
"io"
"net/url"
Expand All @@ -26,7 +27,6 @@ import (
"testing"

"github.com/opencontainers/image-spec/schema"
"github.com/pkg/errors"
"github.com/russross/blackfriday"
)

Expand Down Expand Up @@ -93,7 +93,7 @@ func validate(t *testing.T, name string) {
}

for _, example := range examples {
if example.Err == errFormatInvalid && example.Mediatype == "" { // ignore
if errors.Is(example.Err, errFormatInvalid) && example.Mediatype == "" { // ignore
continue
}

Expand All @@ -111,7 +111,8 @@ func validate(t *testing.T, name string) {
}

var errs []error
if verr, ok := errors.Cause(err).(schema.ValidationError); ok {
var verr schema.ValidationError
if errors.As(err, &verr) {
errs = verr.Errs
} else {
printFields(t, "error", example.Mediatype, example.Title, err)
Expand Down
29 changes: 14 additions & 15 deletions schema/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ package schema
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io"
"regexp"

digest "github.com/opencontainers/go-digest"
v1 "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors"
"github.com/xeipuuv/gojsonschema"
)

Expand Down Expand Up @@ -53,7 +53,7 @@ func (e ValidationError) Error() string {
func (v Validator) Validate(src io.Reader) error {
buf, err := io.ReadAll(src)
if err != nil {
return errors.Wrap(err, "unable to read the document file")
return fmt.Errorf("unable to read the document file: %w", err)
}

if f, ok := mapValidate[v]; ok {
Expand All @@ -71,9 +71,8 @@ func (v Validator) Validate(src io.Reader) error {

result, err := gojsonschema.Validate(sl, ml)
if err != nil {
return errors.Wrapf(
WrapSyntaxError(bytes.NewReader(buf), err),
"schema %s: unable to validate", v)
return fmt.Errorf("schema %s: unable to validate: %w", v,
WrapSyntaxError(bytes.NewReader(buf), err))
}

if result.Valid() {
Expand Down Expand Up @@ -101,12 +100,12 @@ func validateManifest(r io.Reader) error {

buf, err := io.ReadAll(r)
if err != nil {
return errors.Wrapf(err, "error reading the io stream")
return fmt.Errorf("error reading the io stream: %w", err)
}

err = json.Unmarshal(buf, &header)
if err != nil {
return errors.Wrap(err, "manifest format mismatch")
return fmt.Errorf("manifest format mismatch: %w", err)
}

if header.Config.MediaType != string(v1.MediaTypeImageConfig) {
Expand All @@ -131,16 +130,16 @@ func validateDescriptor(r io.Reader) error {

buf, err := io.ReadAll(r)
if err != nil {
return errors.Wrapf(err, "error reading the io stream")
return fmt.Errorf("error reading the io stream: %w", err)
}

err = json.Unmarshal(buf, &header)
if err != nil {
return errors.Wrap(err, "descriptor format mismatch")
return fmt.Errorf("descriptor format mismatch: %w", err)
}

err = header.Digest.Validate()
if err == digest.ErrDigestUnsupported {
if errors.Is(err, digest.ErrDigestUnsupported) {
// we ignore unsupported algorithms
fmt.Printf("warning: unsupported digest: %q: %v\n", header.Digest, err)
return nil
Expand All @@ -153,12 +152,12 @@ func validateIndex(r io.Reader) error {

buf, err := io.ReadAll(r)
if err != nil {
return errors.Wrapf(err, "error reading the io stream")
return fmt.Errorf("error reading the io stream: %w", err)
}

err = json.Unmarshal(buf, &header)
if err != nil {
return errors.Wrap(err, "index format mismatch")
return fmt.Errorf("index format mismatch: %w", err)
}

for _, manifest := range header.Manifests {
Expand All @@ -180,12 +179,12 @@ func validateConfig(r io.Reader) error {

buf, err := io.ReadAll(r)
if err != nil {
return errors.Wrapf(err, "error reading the io stream")
return fmt.Errorf("error reading the io stream: %w", err)
}

err = json.Unmarshal(buf, &header)
if err != nil {
return errors.Wrap(err, "config format mismatch")
return fmt.Errorf("config format mismatch: %w", err)
}

checkPlatform(header.OS, header.Architecture)
Expand All @@ -194,7 +193,7 @@ func validateConfig(r io.Reader) error {
envRegexp := regexp.MustCompile(`^[^=]+=.*$`)
for _, e := range header.Config.Env {
if !envRegexp.MatchString(e) {
return errors.Errorf("unexpected env: %q", e)
return fmt.Errorf("unexpected env: %q", e)
}
}

Expand Down

0 comments on commit d881fa8

Please sign in to comment.