cli/cli · error · ErrAttestationFileCreation
failed to marshall attestation to JSON while writing to file
Error message
failed to marshall attestation to JSON while writing to file: %v
What it means
Specific cause joined with ErrAttestationFileCreation when encoding/json cannot marshal an attestation bundle to JSON while writing the .jsonl file. json.Marshal only fails on unsupported values (NaN, cycles, channels, functions), so in practice this signals a corrupted or unexpectedly-shaped in-memory bundle rather than ordinary data.
Source
Thrown at pkg/cmd/attestation/download/metadata.go:53
return path
}
func (s *LiveStore) createMetadataFile(artifactDigest string, attestationsResp []*api.Attestation) (string, error) {
metadataFilePath := s.createJSONLinesFilePath(artifactDigest)
f, err := os.Create(metadataFilePath)
if err != nil {
return "", errors.Join(ErrAttestationFileCreation, fmt.Errorf("failed to create file: %v", err))
}
for _, resp := range 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: %v", err))
}
return "", errors.Join(ErrAttestationFileCreation, fmt.Errorf("failed to marshall attestation to JSON while writing to file: %v", err))
}
withNewline := fmt.Sprintf("%s\n", attBytes)
_, err = f.Write([]byte(withNewline))
if err != nil {
if err = f.Close(); err != nil {
return "", errors.Join(ErrAttestationFileCreation, fmt.Errorf("failed to close file while handling write error: %v", err))
}
return "", errors.Join(ErrAttestationFileCreation, fmt.Errorf("failed to write attestations: %v", err))
}
}
if err = f.Close(); err != nil {
return "", errors.Join(ErrAttestationFileCreation, fmt.Errorf("failed to close file after writing attestations: %v", err))
}
return metadataFilePath, nilView on GitHub (pinned to 0eeec0b92e)
Solutions
- Re-download the attestations: the fetched data may have been corrupted
- Inspect the bundle offline with `gh attestation inspect <file>` to see if it parses
- Report upstream if a well-formed attestation reproduces the failure
Defensive patterns
Strategy: retry
Try / catch
b, err := json.Marshal(bundle)
if err != nil {
_ = f.Close()
return fmt.Errorf("marshal bundle %s: %w", digest, err)
} Prevention
- Re-fetch attestations when marshal fails; suspect corrupted fetched data
- Pin gh versions in CI so bundle schemas match the encoder's expectations
- Report reproducible marshal failures upstream with the bundle attached
When it happens
Trigger: json.Marshal(resp.Bundle) errors inside the per-attestation loop of createMetadataFile, e.g. a bundle containing values the encoder cannot serialize.
Common situations: Very rare; can appear if the fetched attestation payload was truncated or if a code change introduced a custom type without MarshalJSON support.
Related errors
- failed to close file while marshalling JSON: %v
- failed to marshal predicate: %v
- error marshaling request: %w
- failed to unmarshal to bundle: %w
- failed to close file while handling write error: %v
AI-assisted analysis of cli/cli@0eeec0b92e (2026-08-15).
Data as JSON: /api/errors/05fe4a49a2eb2b1f.
Report an issue: GitHub.