Skip to content
This repository has been archived by the owner on May 26, 2023. It is now read-only.

improves error message in cache #38

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ociclient/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func (lc *layeredCache) get(dgst string, desc ocispecv1.Descriptor) (os.FileInfo
if err := lc.baseFs.Remove(dgst); err != nil {
lc.log.V(7).Info("unable to remove invalid blob", "digest", dgst, "err", err.Error())
}
return info, nil, ErrNotFound
return info, nil, ErrInvalidBlob
}
file, err := lc.baseFs.OpenFile(dgst, os.O_RDONLY, os.ModePerm)
if err != nil {
Expand Down Expand Up @@ -231,7 +231,7 @@ func (lc *layeredCache) getFromOverlay(dgst string, desc ocispecv1.Descriptor) (
if err := lc.overlayFs.Remove(dgst); err != nil {
lc.log.V(7).Info("unable to remove invalid blob", "digest", dgst, "err", err.Error())
}
return info, nil, ErrNotFound
return info, nil, ErrInvalidBlob
}
file, err := lc.overlayFs.OpenFile(dgst, os.O_RDONLY, os.ModePerm)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions ociclient/cache/cache_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ var _ = Describe("Cache", func() {

_, err = c.Get(desc)
Expect(err).To(HaveOccurred())
Expect(err).To(Equal(ErrNotFound))
Expect(err).To(Equal(ErrInvalidBlob))
})

It("should detect tampered data (size shortcut) and remove the tempered blob", func() {
Expand All @@ -87,7 +87,7 @@ var _ = Describe("Cache", func() {

_, err = c.Get(desc)
Expect(err).To(HaveOccurred())
Expect(err).To(Equal(ErrNotFound))
Expect(err).To(Equal(ErrInvalidBlob))
})

Context("metrics", func() {
Expand Down
5 changes: 4 additions & 1 deletion ociclient/cache/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ import (
)

var (
// ErrNotFound is a error that indicates that the file is not cached
// ErrNotFound is an error that indicates that the file is not cached
ErrNotFound = errors.New("not cached")

// ErrInvalidBlob is an error that indicates that a blob is invalid
ErrInvalidBlob = errors.New("invalid blob")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if we need a dedicated error for this.
MAybe it would be more helpful to return the real error with fmt.Errorf("invalid blob: %w", err)

)

// CacheDirEnvName is the name of the environment variable that configures cache directory.
Expand Down