OpenNHP/opennhp · error
fail to unmarshal confidential computing result
Error message
fail to unmarshal confidential computing result: %s
What it means
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.
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 '{')
Example fix
// before
var structResult map[string]any
err := json.Unmarshal([]byte(taRes), &structResult)
// after
if !json.Valid([]byte(taRes)) {
return nil, fmt.Errorf("TA returned non-JSON: %q", taRes)
}
var structResult map[string]any
err := json.Unmarshal([]byte(taRes), &structResult) Defensive patterns
Strategy: type-guard
Validate before calling
if taRes == "" || !json.Valid([]byte(taRes)) {
return fmt.Errorf("TA returned non-JSON payload")
} Type guard
func isJSONObject(s string) bool {
var m map[string]any
return json.Unmarshal([]byte(s), &m) == nil && m != nil
} Try / catch
res, err := a.AccessData(...)
if err != nil && strings.Contains(err.Error(), "fail to unmarshal confidential computing result") {
log.Errorf("unexpected TA response: %v", err)
// inspect raw TA response / check TA version compatibility
} Prevention
- 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
When it happens
Trigger: CallTrustedApplication returned a taRes string that is not valid JSON or not a JSON object (HTML error page, empty string, JSON array, quoted string).
Common situations: TA behind a proxy returning an error page with 200; TA function changed its response schema; truncated response; version drift between agent and TA.
Understand the failure class
Background: "failed to unmarshal" / json.Unmarshal errors: why parsing a response into a Go struct fails and how to fix it — this error's family across 23 libraries.
Related errors
- Failed to refresh SDP
- Error: fail to find policyId for ztdoId
- fail to call trusted application with error
- failed to unmarshal data private key wrapping
- Error: fail to generating temporary file path
AI-assisted analysis of OpenNHP/opennhp@6e04ca5ff0 (2026-09-07).
Data as JSON: /api/errors/e64995a923b9eedd.
Report an issue: GitHub.
Appendix: source
Thrown at endpoints/agent/udpagent.go:1297
}
// inject data path to params
params["path"] = output
var exist bool
if policyId, exist = a.smartPolicyIdentifier[ztdoId]; !exist {
return nil, fmt.Errorf("Error: fail to find policyId for ztdoId %s.\n", ztdoId)
}
taRes, err := a.CallTrustedApplication(taId, function, params, policyId)
if err != nil {
return nil, fmt.Errorf("fail to call trusted application with error: %s\n", err.Error())
} else {
var structResult map[string]any
err := json.Unmarshal([]byte(taRes), &structResult)
if err != nil {
return nil, fmt.Errorf("fail to unmarshal confidential computing result: %s\n", err.Error())
}
return structResult, nil
}
}
func (a *UdpAgent) PreCheckDataAccess(ztdoId string) (output string, refreshSdp bool, decrypted bool) {
output = ""
// Check whether the smart data policy needs to be refreshed
if sdpRefreshTime, exist := a.smartDataPolicyRefreshTime[ztdoId]; exist {
if time.Now().UnixNano()-sdpRefreshTime > SmartDataPolicyRefreshTime {
refreshSdp = true
}
} else {
refreshSdp = true
}
View on GitHub (pinned to 6e04ca5ff0)