Skip to content

Commit

Permalink
fix: error handling when delete
Browse files Browse the repository at this point in the history
Signed-off-by: Xiaoxuan Wang <[email protected]>
  • Loading branch information
wangxiaoxuan273 committed Oct 24, 2023
1 parent 0f1dc30 commit cbfdc47
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
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)
}
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)
}
}

0 comments on commit cbfdc47

Please sign in to comment.