{"record":{"id":"05fe4a49a2eb2b1f","repo":"cli/cli","slug":"failed-to-marshall-attestation-to-json-while-writi","errorCode":null,"errorMessage":"failed to marshall attestation to JSON while writing to file: %v","messagePattern":"failed to marshall attestation to JSON while writing to file: (.+?)","errorType":"exception","errorClass":"ErrAttestationFileCreation","httpStatus":null,"severity":"error","filePath":"pkg/cmd/attestation/download/metadata.go","lineNumber":53,"sourceCode":"\treturn path\n}\n\nfunc (s *LiveStore) createMetadataFile(artifactDigest string, attestationsResp []*api.Attestation) (string, error) {\n\tmetadataFilePath := s.createJSONLinesFilePath(artifactDigest)\n\n\tf, err := os.Create(metadataFilePath)\n\tif err != nil {\n\t\treturn \"\", errors.Join(ErrAttestationFileCreation, fmt.Errorf(\"failed to create file: %v\", err))\n\t}\n\n\tfor _, resp := range attestationsResp {\n\t\tbundle := resp.Bundle\n\t\tattBytes, err := json.Marshal(bundle)\n\t\tif err != nil {\n\t\t\tif err = f.Close(); err != nil {\n\t\t\t\treturn \"\", errors.Join(ErrAttestationFileCreation, fmt.Errorf(\"failed to close file while marshalling JSON: %v\", err))\n\t\t\t}\n\t\t\treturn \"\", errors.Join(ErrAttestationFileCreation, fmt.Errorf(\"failed to marshall attestation to JSON while writing to file: %v\", err))\n\t\t}\n\n\t\twithNewline := fmt.Sprintf(\"%s\\n\", attBytes)\n\t\t_, err = f.Write([]byte(withNewline))\n\t\tif err != nil {\n\t\t\tif err = f.Close(); err != nil {\n\t\t\t\treturn \"\", errors.Join(ErrAttestationFileCreation, fmt.Errorf(\"failed to close file while handling write error: %v\", err))\n\t\t\t}\n\n\t\t\treturn \"\", errors.Join(ErrAttestationFileCreation, fmt.Errorf(\"failed to write attestations: %v\", err))\n\t\t}\n\t}\n\n\tif err = f.Close(); err != nil {\n\t\treturn \"\", errors.Join(ErrAttestationFileCreation, fmt.Errorf(\"failed to close file after writing attestations: %v\", err))\n\t}\n\n\treturn metadataFilePath, nil","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/cli/cli/blob/0eeec0b92edbe70199f9768522f831d3534f41ad/pkg/cmd/attestation/download/metadata.go#L35-L71","documentation":"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.","triggerScenarios":"json.Marshal(resp.Bundle) errors inside the per-attestation loop of createMetadataFile, e.g. a bundle containing values the encoder cannot serialize.","commonSituations":"Very rare; can appear if the fetched attestation payload was truncated or if a code change introduced a custom type without MarshalJSON support.","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"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"b, err := json.Marshal(bundle)\nif err != nil {\n\t_ = f.Close()\n\treturn fmt.Errorf(\"marshal bundle %s: %w\", digest, err)\n}","preventionTips":["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"],"tags":["json","attestation","serialization","edge-case"],"backgroundTag":null,"analyzedSha":"0eeec0b92edbe70199f9768522f831d3534f41ad","analyzedAt":"2026-08-15T12:31:05.478Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}