{"record":{"id":"69e7ae4f075b5dce","repo":"OpenNHP/opennhp","slug":"failed-to-marshal-evidence-v","errorCode":null,"errorMessage":"failed to marshal evidence: %v","messagePattern":"failed to marshal evidence: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nhp/core/wasm/engine/host.go","lineNumber":83,"sourceCode":"\n\treturn compressedBody, nil\n}\n\nfunc GetEvidenceWithAgentUuid() ([]byte, error) {\n\tagentUniqueId, err := CalculateAgentUniqueId()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to get agent unique id: %v\", err)\n\t}\n\n\tevidence := map[string]any{\n\t\t\"test_purpose\":  \"this evidence is for testing purposes only\",\n\t\t\"measure\":       agentUniqueId,\n\t\t\"serial_number\": agentUniqueId,\n\t}\n\n\tevidenceBytes, err := json.Marshal(evidence)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to marshal evidence: %v\", err)\n\t}\n\n\tvar buf bytes.Buffer\n\tw := zlib.NewWriter(&buf)\n\t_, err = w.Write(evidenceBytes)\n\tw.Close()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to compress response body: %w\", err)\n\t}\n\n\treturn buf.Bytes(), nil\n}\n\nfunc GetEvidence() (string, error) {\n\tevidence, err := GetEvidenceWithCCUrl()\n\tif err != nil {\n\t\tevidence, err = GetEvidenceWithAgentUuid()\n\t\tif err != nil {","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/OpenNHP/opennhp/blob/6e04ca5ff03222a699c24205cd4bf8fee9af7ffe/nhp/core/wasm/engine/host.go#L65-L101","documentation":"GetEvidenceWithAgentUuid builds an evidence map (measure/serial_number keyed by the agent unique id) and serializes it to JSON before zlib compression. This error wraps any json.Marshal failure. Since the map values are plain strings, failures are extremely rare but would indicate a marshaling-engine problem.","triggerScenarios":"json.Marshal(evidence) returns an error inside GetEvidenceWithAgentUuid (nhp/core/wasm/engine/host.go:83). Practically only occurs if the evidence map contains unsupported types or a custom marshaler errors.","commonSituations":"Custom json.Marshaler implementations on map values returning errors; corrupted agentUniqueId producing a value type whose MarshalJSON fails after code changes.","solutions":["Log the wrapped err (%v) to see the underlying marshal failure detail","Verify the evidence map only contains JSON-serializable values (strings, numbers)","Check for custom MarshalJSON methods on values added to the evidence map"],"exampleFix":"// before\nevidenceBytes, err := json.Marshal(evidence)\nif err != nil {\n\treturn nil, fmt.Errorf(\"failed to marshal evidence: %v\", err)\n}\n// after\nevidenceBytes, err := json.Marshal(evidence)\nif err != nil {\n\treturn nil, fmt.Errorf(\"failed to marshal evidence: %w\", err)\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"evidence, err := GetEvidenceWithAgentUuid()\nif err != nil {\n\tvar marshalErr error\n\tif errors.Is(err, json.UnsupportedTypeError) || errors.As(err, &marshalErr) {\n\t\t// handle non-serializable evidence content\n\t}\n\treturn err\n}","preventionTips":["Keep evidence map values restricted to JSON-native types (string, number)","Avoid custom MarshalJSON implementations that can fail"],"tags":["go","json","serialization","wasm"],"backgroundTag":"json-marshal-failed","analyzedSha":"6e04ca5ff03222a699c24205cd4bf8fee9af7ffe","analyzedAt":"2026-09-07T15:44:59.941Z","contentChangedAt":"2026-09-07T15:44:59.941Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}