chore: refactor cache to use errors pkg

Signed-off-by: Justin Chadwell <me@jedevc.com>
This commit is contained in:
Justin Chadwell
2022-11-23 11:06:54 +00:00
parent f9234cca46
commit feaba880de
3 changed files with 8 additions and 9 deletions

View File

@@ -7,7 +7,6 @@ import (
"compress/gzip"
"context"
"encoding/json"
"fmt"
"io"
"github.com/containerd/containerd/content"
@@ -50,11 +49,11 @@ func needsForceCompression(ctx context.Context, cs content.Store, source ocispec
func MergeNydus(ctx context.Context, ref ImmutableRef, comp compression.Config, s session.Group) (*ocispecs.Descriptor, error) {
iref, ok := ref.(*immutableRef)
if !ok {
return nil, fmt.Errorf("unsupported ref")
return nil, errors.Errorf("unsupported ref type %T", ref)
}
refs := iref.layerChain()
if len(refs) == 0 {
return nil, fmt.Errorf("refs can't be empty")
return nil, errors.Errorf("refs can't be empty")
}
// Extracts nydus bootstrap from nydus format for each layer.

View File

@@ -1454,7 +1454,7 @@ func ensurePrune(ctx context.Context, t *testing.T, cm Manager, pruneNum, maxRet
func getCompressor(w io.Writer, compressionType compression.Type, customized bool) (io.WriteCloser, error) {
switch compressionType {
case compression.Uncompressed:
return nil, fmt.Errorf("compression is not requested: %v", compressionType)
return nil, errors.Errorf("compression is not requested: %v", compressionType)
case compression.Gzip:
if customized {
gz, _ := gzip.NewWriterLevel(w, gzip.NoCompression)
@@ -1495,7 +1495,7 @@ func getCompressor(w io.Writer, compressionType compression.Type, customized boo
}
return zstd.NewWriter(w)
default:
return nil, fmt.Errorf("unknown compression type: %q", compressionType)
return nil, errors.Errorf("unknown compression type: %q", compressionType)
}
}

8
cache/refs.go vendored
View File

@@ -836,11 +836,11 @@ func getBlobDesc(ctx context.Context, cs content.Store, dgst digest.Digest) (oci
return ocispecs.Descriptor{}, err
}
if info.Labels == nil {
return ocispecs.Descriptor{}, fmt.Errorf("no blob metadata is stored for %q", info.Digest)
return ocispecs.Descriptor{}, errors.Errorf("no blob metadata is stored for %q", info.Digest)
}
mt, ok := info.Labels[blobMediaTypeLabel]
if !ok {
return ocispecs.Descriptor{}, fmt.Errorf("no media type is stored for %q", info.Digest)
return ocispecs.Descriptor{}, errors.Errorf("no media type is stored for %q", info.Digest)
}
desc := ocispecs.Descriptor{
Digest: info.Digest,
@@ -1550,12 +1550,12 @@ func readonlyOverlay(opt []string) []string {
func newSharableMountPool(tmpdirRoot string) (sharableMountPool, error) {
if tmpdirRoot != "" {
if err := os.MkdirAll(tmpdirRoot, 0700); err != nil {
return sharableMountPool{}, fmt.Errorf("failed to prepare mount pool: %w", err)
return sharableMountPool{}, errors.Wrap(err, "failed to prepare mount pool")
}
// If tmpdirRoot is specified, remove existing mounts to avoid conflict.
files, err := os.ReadDir(tmpdirRoot)
if err != nil {
return sharableMountPool{}, fmt.Errorf("failed to read mount pool: %w", err)
return sharableMountPool{}, errors.Wrap(err, "failed to read mount pool")
}
for _, file := range files {
if file.IsDir() {