{"record":{"id":"e64995a923b9eedd","repo":"OpenNHP/opennhp","slug":"fail-to-unmarshal-confidential-computing-result","errorCode":null,"errorMessage":"fail to unmarshal confidential computing result: %s\n","messagePattern":"fail to unmarshal confidential computing result: (.+?)\n","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"endpoints/agent/udpagent.go","lineNumber":1297,"sourceCode":"\t}\n\n\t// inject data path to params\n\tparams[\"path\"] = output\n\n\tvar exist bool\n\tif policyId, exist = a.smartPolicyIdentifier[ztdoId]; !exist {\n\t\treturn nil, fmt.Errorf(\"Error: fail to find policyId for ztdoId %s.\\n\", ztdoId)\n\t}\n\n\ttaRes, err := a.CallTrustedApplication(taId, function, params, policyId)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"fail to call trusted application with error: %s\\n\", err.Error())\n\t} else {\n\t\tvar structResult map[string]any\n\n\t\terr := json.Unmarshal([]byte(taRes), &structResult)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"fail to unmarshal confidential computing result: %s\\n\", err.Error())\n\t\t}\n\n\t\treturn structResult, nil\n\t}\n}\n\nfunc (a *UdpAgent) PreCheckDataAccess(ztdoId string) (output string, refreshSdp bool, decrypted bool) {\n\toutput = \"\"\n\n\t// Check whether the smart data policy needs to be refreshed\n\tif sdpRefreshTime, exist := a.smartDataPolicyRefreshTime[ztdoId]; exist {\n\t\tif time.Now().UnixNano()-sdpRefreshTime > SmartDataPolicyRefreshTime {\n\t\t\trefreshSdp = true\n\t\t}\n\t} else {\n\t\trefreshSdp = true\n\t}\n","sourceCodeStart":1279,"sourceCodeEnd":1315,"githubUrl":"https://github.com/OpenNHP/opennhp/blob/6e04ca5ff03222a699c24205cd4bf8fee9af7ffe/endpoints/agent/udpagent.go#L1279-L1315","documentation":"After a successful trusted-application call, the raw JSON result is unmarshaled into map[string]any; failure to parse yields this error. It means the TA responded but its body was not the expected JSON object shape.","triggerScenarios":"CallTrustedApplication returned a taRes string that is not valid JSON or not a JSON object (HTML error page, empty string, JSON array, quoted string).","commonSituations":"TA behind a proxy returning an error page with 200; TA function changed its response schema; truncated response; version drift between agent and TA.","solutions":["Log/inspect the raw taRes string before unmarshaling","Confirm the TA function's current response schema and update parsing code","Handle non-object payloads explicitly (check taRes is non-empty, starts with '{')"],"exampleFix":"// before\nvar structResult map[string]any\nerr := json.Unmarshal([]byte(taRes), &structResult)\n// after\nif !json.Valid([]byte(taRes)) {\n    return nil, fmt.Errorf(\"TA returned non-JSON: %q\", taRes)\n}\nvar structResult map[string]any\nerr := json.Unmarshal([]byte(taRes), &structResult)","handlingStrategy":"type-guard","validationCode":"if taRes == \"\" || !json.Valid([]byte(taRes)) {\n    return fmt.Errorf(\"TA returned non-JSON payload\")\n}","typeGuard":"func isJSONObject(s string) bool {\n    var m map[string]any\n    return json.Unmarshal([]byte(s), &m) == nil && m != nil\n}","tryCatchPattern":"res, err := a.AccessData(...)\nif err != nil && strings.Contains(err.Error(), \"fail to unmarshal confidential computing result\") {\n    log.Errorf(\"unexpected TA response: %v\", err)\n    // inspect raw TA response / check TA version compatibility\n}","preventionTips":["Log raw TA responses in a debug mode","Pin/verify TA response schema versions in integration tests","Detect HTML/proxy error pages before JSON parsing"],"tags":["json","dhp","confidential-computing"],"backgroundTag":"json-unmarshal-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"}