@@ -17,13 +17,13 @@ package schema
1717import (
1818 "bytes"
1919 "encoding/json"
20+ "errors"
2021 "fmt"
2122 "io"
2223 "regexp"
2324
2425 digest "github.com/opencontainers/go-digest"
2526 v1 "github.com/opencontainers/image-spec/specs-go/v1"
26- "github.com/pkg/errors"
2727 "github.com/xeipuuv/gojsonschema"
2828)
2929
@@ -53,7 +53,7 @@ func (e ValidationError) Error() string {
5353func (v Validator ) Validate (src io.Reader ) error {
5454 buf , err := io .ReadAll (src )
5555 if err != nil {
56- return errors . Wrap ( err , "unable to read the document file" )
56+ return fmt . Errorf ( "unable to read the document file: %w" , err )
5757 }
5858
5959 if f , ok := mapValidate [v ]; ok {
@@ -71,9 +71,8 @@ func (v Validator) Validate(src io.Reader) error {
7171
7272 result , err := gojsonschema .Validate (sl , ml )
7373 if err != nil {
74- return errors .Wrapf (
75- WrapSyntaxError (bytes .NewReader (buf ), err ),
76- "schema %s: unable to validate" , v )
74+ return fmt .Errorf ("schema %s: unable to validate: %w" , v ,
75+ WrapSyntaxError (bytes .NewReader (buf ), err ))
7776 }
7877
7978 if result .Valid () {
@@ -101,12 +100,12 @@ func validateManifest(r io.Reader) error {
101100
102101 buf , err := io .ReadAll (r )
103102 if err != nil {
104- return errors . Wrapf ( err , "error reading the io stream" )
103+ return fmt . Errorf ( "error reading the io stream: %w" , err )
105104 }
106105
107106 err = json .Unmarshal (buf , & header )
108107 if err != nil {
109- return errors . Wrap ( err , "manifest format mismatch" )
108+ return fmt . Errorf ( "manifest format mismatch: %w" , err )
110109 }
111110
112111 if header .Config .MediaType != string (v1 .MediaTypeImageConfig ) {
@@ -131,16 +130,16 @@ func validateDescriptor(r io.Reader) error {
131130
132131 buf , err := io .ReadAll (r )
133132 if err != nil {
134- return errors . Wrapf ( err , "error reading the io stream" )
133+ return fmt . Errorf ( "error reading the io stream: %w" , err )
135134 }
136135
137136 err = json .Unmarshal (buf , & header )
138137 if err != nil {
139- return errors . Wrap ( err , "descriptor format mismatch" )
138+ return fmt . Errorf ( "descriptor format mismatch: %w" , err )
140139 }
141140
142141 err = header .Digest .Validate ()
143- if err == digest .ErrDigestUnsupported {
142+ if errors . Is ( err , digest .ErrDigestUnsupported ) {
144143 // we ignore unsupported algorithms
145144 fmt .Printf ("warning: unsupported digest: %q: %v\n " , header .Digest , err )
146145 return nil
@@ -153,12 +152,12 @@ func validateIndex(r io.Reader) error {
153152
154153 buf , err := io .ReadAll (r )
155154 if err != nil {
156- return errors . Wrapf ( err , "error reading the io stream" )
155+ return fmt . Errorf ( "error reading the io stream: %w" , err )
157156 }
158157
159158 err = json .Unmarshal (buf , & header )
160159 if err != nil {
161- return errors . Wrap ( err , "index format mismatch" )
160+ return fmt . Errorf ( "index format mismatch: %w" , err )
162161 }
163162
164163 for _ , manifest := range header .Manifests {
@@ -180,12 +179,12 @@ func validateConfig(r io.Reader) error {
180179
181180 buf , err := io .ReadAll (r )
182181 if err != nil {
183- return errors . Wrapf ( err , "error reading the io stream" )
182+ return fmt . Errorf ( "error reading the io stream: %w" , err )
184183 }
185184
186185 err = json .Unmarshal (buf , & header )
187186 if err != nil {
188- return errors . Wrap ( err , "config format mismatch" )
187+ return fmt . Errorf ( "config format mismatch: %w" , err )
189188 }
190189
191190 checkPlatform (header .OS , header .Architecture )
@@ -194,7 +193,7 @@ func validateConfig(r io.Reader) error {
194193 envRegexp := regexp .MustCompile (`^[^=]+=.*$` )
195194 for _ , e := range header .Config .Env {
196195 if ! envRegexp .MatchString (e ) {
197- return errors .Errorf ("unexpected env: %q" , e )
196+ return fmt .Errorf ("unexpected env: %q" , e )
198197 }
199198 }
200199
0 commit comments