Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: error handling when delete non-existent target #627

Merged
merged 3 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 7 additions & 0 deletions content/oci/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ func (s *Storage) Push(_ context.Context, expected ocispec.Descriptor, content i

// Delete removes the target from the system.
func (s *Storage) Delete(ctx context.Context, target ocispec.Descriptor) error {
exists, err := s.Exists(ctx, target)
if err != nil {
return err
}
if !exists {
return fmt.Errorf("target to delete is not present in the storage: %w", errdef.ErrNotFound)
}
Wwwsylvia marked this conversation as resolved.
Show resolved Hide resolved
path, err := blobPath(target.Digest)
if err != nil {
return fmt.Errorf("%s: %s: %w", target.Digest, target.MediaType, errdef.ErrInvalidDigest)
Expand Down
4 changes: 4 additions & 0 deletions content/oci/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,4 +412,8 @@ func TestStorage_Delete(t *testing.T) {
if exists {
t.Errorf("Storage.Exists() = %v, want %v", exists, false)
}
err = s.Delete(ctx, desc)
if !errors.Is(err, errdef.ErrNotFound) {
t.Fatalf("got error = %v, want %v", err, errdef.ErrNotFound)
}
}
Loading