diff --git a/manifest/ocischema/builder.go b/manifest/ocischema/builder.go index c189a16e..023a8a0b 100644 --- a/manifest/ocischema/builder.go +++ b/manifest/ocischema/builder.go @@ -2,6 +2,7 @@ package ocischema import ( "context" + "errors" "github.com/docker/distribution" "github.com/docker/distribution/manifest" @@ -45,12 +46,13 @@ func NewManifestBuilder(bs distribution.BlobService, configJSON []byte, annotati // SetMediaType assigns the passed mediatype or error if the mediatype is not a // valid media type for oci image manifests currently: "" or "application/vnd.oci.image.manifest.v1+json" -func (mb *Builder) SetMediaType(mediaType string) { +func (mb *Builder) SetMediaType(mediaType string) error { if mediaType != "" && mediaType != v1.MediaTypeImageManifest { - panic("Invalid media type for OCI image manifest") + return errors.New("Invalid media type for OCI image manifest") } mb.mediaType = mediaType + return nil } // Build produces a final manifest from the given references. diff --git a/registry/storage/manifeststore_test.go b/registry/storage/manifeststore_test.go index 6e583c53..c6a2ba06 100644 --- a/registry/storage/manifeststore_test.go +++ b/registry/storage/manifeststore_test.go @@ -390,7 +390,10 @@ func testOCIManifestStorage(t *testing.T, testname string, includeMediaTypes boo blobStore := env.repository.Blobs(ctx) builder := ocischema.NewManifestBuilder(blobStore, []byte{}, map[string]string{}) - builder.(*ocischema.Builder).SetMediaType(imageMediaType) + err = builder.(*ocischema.Builder).SetMediaType(imageMediaType) + if err != nil { + t.Fatal(err) + } // Add some layers for i := 0; i < 2; i++ {