From ead84a2acc14b0625988e2cc678b7c85adaed06e Mon Sep 17 00:00:00 2001 From: Meredith Lancaster Date: Thu, 14 Mar 2024 21:35:30 -0600 Subject: [PATCH] close file in error handling branch Signed-off-by: Meredith Lancaster --- pkg/cmd/attestation/download/metadata.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkg/cmd/attestation/download/metadata.go b/pkg/cmd/attestation/download/metadata.go index 49b152859..4b2c0e9d1 100644 --- a/pkg/cmd/attestation/download/metadata.go +++ b/pkg/cmd/attestation/download/metadata.go @@ -39,6 +39,9 @@ func (s *LiveStore) createMetadataFile(artifactDigest string, attestationsResp [ bundle := resp.Bundle attBytes, err := json.Marshal(bundle) if err != nil { + if err = f.Close(); err != nil { + return "", errors.Join(ErrAttestationFileCreation, fmt.Errorf("failed to close file while marshalling JSON: %w", err)) + } return "", errors.Join(ErrAttestationFileCreation, fmt.Errorf("failed to marshall attestation to JSON while writing to file: %w", err)) }