close file in error handling branch

Signed-off-by: Meredith Lancaster <malancas@github.com>
This commit is contained in:
Meredith Lancaster 2024-03-14 21:35:30 -06:00
parent 79fa437969
commit ead84a2acc

View file

@ -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))
}