Make error more obvious when bundle has wrong extension

This commit is contained in:
William Martin 2024-04-24 15:50:29 +02:00
parent 93113e12ea
commit 054b306d09
2 changed files with 3 additions and 3 deletions

View file

@ -13,7 +13,7 @@ import (
"github.com/sigstore/sigstore-go/pkg/bundle" "github.com/sigstore/sigstore-go/pkg/bundle"
) )
var ErrLocalAttestations = errors.New("failed to load local attestations") var ErrUnrecognisedBundleExtension = errors.New("bundle file extension not supported, must be json or jsonl")
type FetchAttestationsConfig struct { type FetchAttestationsConfig struct {
APIClient api.Client APIClient api.Client
@ -52,7 +52,7 @@ func GetLocalAttestations(path string) ([]*api.Attestation, error) {
} }
return attestations, nil return attestations, nil
} }
return nil, ErrLocalAttestations return nil, ErrUnrecognisedBundleExtension
} }
func loadBundleFromJSONFile(path string) ([]*api.Attestation, error) { func loadBundleFromJSONFile(path string) ([]*api.Attestation, error) {

View file

@ -48,7 +48,7 @@ func TestGetLocalAttestations(t *testing.T) {
path := "../test/data/sigstore-js-2.1.0-bundles.tgz" path := "../test/data/sigstore-js-2.1.0-bundles.tgz"
attestations, err := GetLocalAttestations(path) attestations, err := GetLocalAttestations(path)
require.ErrorIs(t, err, ErrLocalAttestations) require.ErrorIs(t, err, ErrUnrecognisedBundleExtension)
require.Nil(t, attestations) require.Nil(t, attestations)
}) })
} }