{"record":{"id":"f6087740b147f1a9","repo":"nats-io/nats-server","slug":"unable-to-marshal-keys-to-json-v","errorCode":null,"errorMessage":"unable to marshal keys to JSON: %v","messagePattern":"unable to marshal keys to JSON: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/tpm/js_ek_tpm_windows.go","lineNumber":104,"sourceCode":"tpmKeys := natsTPMPersistedKeys{\n\tVersion:    JsKeyTPMVersion,\n\tPrivateKey: make([]byte, base64.StdEncoding.EncodedLen(len(privateBlob))),\n\tPublicKey:  make([]byte, base64.StdEncoding.EncodedLen(len(publicBlob))),\n}\nbase64.StdEncoding.Encode(tpmKeys.PrivateKey, privateBlob)\nbase64.StdEncoding.Encode(tpmKeys.PublicKey, publicBlob)\n// Convert to JSON\nkeysJSON, err := json.Marshal(tpmKeys)\nif err != nil {\n\treturn fmt.Errorf(\"unable to marshal keys to JSON: %v\", err)\n}\n// Write the JSON to a file\nif err := os.WriteFile(filename, keysJSON, 0640); err != nil {\n\treturn fmt.Errorf(\"unable to write keys file to %q: %v\", filename, err)\n}\nreturn nil","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/tpm/js_ek_tpm_windows.go#L86-L122","documentation":"writeTPMKeysToFile failed to serialize the natsTPMPersistedKeys struct (version plus base64-encoded private/public TPM blobs) to JSON before persisting the JetStream key file. In practice json.Marshal on this plain struct of strings/byte slices essentially never fails; if it does, it signals a programming error such as an unsupported field type, not a runtime or I/O problem.","triggerScenarios":"Thrown at server/tpm/js_ek_tpm_windows.go:104 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify the natsTPMPersistedKeys struct only contains JSON-serializable types (version int, base64 byte slices)","Retry the key creation; a transient marshal failure of a plain struct is practically impossible","Inspect the wrapped error to confirm no embedded unsupported values (e.g. channels, funcs) were added to the struct"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"3a66a489d262bf89b71a71c955c94920394532f3","analyzedAt":"2026-09-02T04:41:54.247Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}