@@ -21,6 +21,7 @@ import (
2121 "bufio"
2222 "context"
2323 "encoding/json"
24+ "errors"
2425 "fmt"
2526 "io"
2627 "os"
@@ -34,7 +35,6 @@ import (
3435 "github.com/opencontainers/go-digest"
3536 "github.com/opencontainers/image-spec/identity"
3637 specs "github.com/opencontainers/image-spec/specs-go/v1"
37- "github.com/pkg/errors"
3838 "github.com/sirupsen/logrus"
3939)
4040
@@ -162,7 +162,7 @@ func (e *overlaybdBuilderEngine) UploadLayer(ctx context.Context, idx int) error
162162 layerDir := e .getLayerDir (idx )
163163 desc , err := getFileDesc (path .Join (layerDir , commitFile ), false )
164164 if err != nil {
165- return errors . Wrapf ( err , "failed to get descriptor for layer %d" , idx )
165+ return fmt . Errorf ( "failed to get descriptor for layer %d: %w " , idx , err )
166166 }
167167 if e .overlaybdLayers [idx ].fromDedup {
168168 // validate that the layer digests match if the layer is from dedup
@@ -178,7 +178,7 @@ func (e *overlaybdBuilderEngine) UploadLayer(ctx context.Context, idx int) error
178178 }
179179 if ! e .noUpload {
180180 if err := uploadBlob (ctx , e .pusher , path .Join (layerDir , commitFile ), desc ); err != nil {
181- return errors . Wrapf ( err , "failed to upload layer %d" , idx )
181+ return fmt . Errorf ( "failed to upload layer %d: %w " , idx , err )
182182 }
183183 }
184184 e .overlaybdLayers [idx ].desc = desc
@@ -406,7 +406,7 @@ func (e *overlaybdBuilderEngine) DownloadConvertedLayer(ctx context.Context, idx
406406 if err != nil {
407407 // We should remove the commit file if the download failed to allow for fallback conversion
408408 os .Remove (targetFile ) // Remove any file that may have failed to download
409- return errors . Wrapf ( err , "failed to download layer %d" , idx )
409+ return fmt . Errorf ( "failed to download layer %d: %w " , idx , err )
410410 }
411411 // Mark that this layer is from dedup
412412 e .overlaybdLayers [idx ].fromDedup = true
@@ -425,19 +425,19 @@ func (e *overlaybdBuilderEngine) uploadBaseLayer(ctx context.Context) (specs.Des
425425 tarFile := path .Join (e .workDir , "ext4_64.tar" )
426426 fdes , err := os .Create (tarFile )
427427 if err != nil {
428- return specs.Descriptor {}, errors . Wrapf ( err , "failed to create file %s" , tarFile )
428+ return specs.Descriptor {}, fmt . Errorf ( "failed to create file %s: %w " , tarFile , err )
429429 }
430430 digester := digest .Canonical .Digester ()
431431 countWriter := & writeCountWrapper {w : io .MultiWriter (fdes , digester .Hash ())}
432432 tarWriter := tar .NewWriter (countWriter )
433433
434434 fsrc , err := os .Open (overlaybdBaseLayer )
435435 if err != nil {
436- return specs.Descriptor {}, errors . Wrapf ( err , "failed to open %s" , overlaybdBaseLayer )
436+ return specs.Descriptor {}, fmt . Errorf ( "failed to open %s: %w " , overlaybdBaseLayer , err )
437437 }
438438 fstat , err := os .Stat (overlaybdBaseLayer )
439439 if err != nil {
440- return specs.Descriptor {}, errors . Wrapf ( err , "failed to get info of %s" , overlaybdBaseLayer )
440+ return specs.Descriptor {}, fmt . Errorf ( "failed to get info of %s: %w " , overlaybdBaseLayer , err )
441441 }
442442
443443 if err := tarWriter .WriteHeader (& tar.Header {
@@ -446,13 +446,13 @@ func (e *overlaybdBuilderEngine) uploadBaseLayer(ctx context.Context) (specs.Des
446446 Size : fstat .Size (),
447447 Typeflag : tar .TypeReg ,
448448 }); err != nil {
449- return specs.Descriptor {}, errors . Wrapf ( err , "failed to write tar header" )
449+ return specs.Descriptor {}, fmt . Errorf ( "failed to write tar header: %w" , err )
450450 }
451451 if _ , err := io .Copy (tarWriter , bufio .NewReader (fsrc )); err != nil {
452- return specs.Descriptor {}, errors . Wrapf ( err , "failed to copy IO" )
452+ return specs.Descriptor {}, fmt . Errorf ( "failed to copy IO: %w" , err )
453453 }
454454 if err = tarWriter .Close (); err != nil {
455- return specs.Descriptor {}, errors . Wrapf ( err , "failed to close tar file" )
455+ return specs.Descriptor {}, fmt . Errorf ( "failed to close tar file: %w" , err )
456456 }
457457
458458 baseDesc := specs.Descriptor {
@@ -467,7 +467,7 @@ func (e *overlaybdBuilderEngine) uploadBaseLayer(ctx context.Context) (specs.Des
467467 }
468468 if ! e .noUpload {
469469 if err = uploadBlob (ctx , e .pusher , tarFile , baseDesc ); err != nil {
470- return specs.Descriptor {}, errors . Wrapf ( err , "failed to upload baselayer" )
470+ return specs.Descriptor {}, fmt . Errorf ( "failed to upload baselayer: %w" , err )
471471 }
472472 logrus .Infof ("baselayer uploaded" )
473473 }
0 commit comments