{"record":{"id":"7640d714e3cc5cc5","repo":"Tencent/WeKnora","slug":"decode-response-w-7640d7","errorCode":null,"errorMessage":"decode response: %w","messagePattern":"decode response: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/infrastructure/docparser/mineru_converter.go","lineNumber":168,"sourceCode":"\t\treturn \"\"\n\t}\n\treturn stem\n}\n\nfunc minerUResultLookupKeys(uploadFileName string) []string {\n\tkeys := make([]string, 0, 3)\n\tif stem := minerUResultStem(uploadFileName); stem != \"\" {\n\t\tkeys = append(keys, stem)\n\t}\n\treturn append(keys, \"document\", \"files\")\n}\n\nfunc parseMinerUFileParseResponse(respBody []byte, uploadFileName string) (string, map[string]string, string, error) {\n\tvar envelope struct {\n\t\tResults map[string]mineruFileEntry `json:\"results\"`\n\t}\n\tif err := json.Unmarshal(respBody, &envelope); err != nil {\n\t\treturn \"\", nil, \"\", fmt.Errorf(\"decode response: %w\", err)\n\t}\n\tif len(envelope.Results) == 0 {\n\t\treturn \"\", nil, \"\", nil\n\t}\n\n\tfor _, key := range minerUResultLookupKeys(uploadFileName) {\n\t\tif entry, ok := envelope.Results[key]; ok {\n\t\t\tif entry.MDContent != \"\" || len(entry.Images) > 0 {\n\t\t\t\treturn entry.MDContent, entry.Images, key, nil\n\t\t\t}\n\t\t}\n\t}\n\n\tfor key, entry := range envelope.Results {\n\t\tif entry.MDContent != \"\" || len(entry.Images) > 0 {\n\t\t\treturn entry.MDContent, entry.Images, key, nil\n\t\t}\n\t}","sourceCodeStart":150,"sourceCodeEnd":186,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/infrastructure/docparser/mineru_converter.go#L150-L186","documentation":"parseMinerUFileParseResponse unmarshals the MinerU /file_parse response body into an envelope with a results map. This error means the body is not valid JSON matching that shape — either it isn't JSON at all, or the structure differs (e.g. no top-level 'results' object).","triggerScenarios":"json.Unmarshal(respBody, &envelope) fails: server returned HTML error page with 200, plain-text message, or a JSON layout from a different MinerU version (results key missing/renamed, array instead of object).","commonSituations":"Proxy/gateway error page returned with HTTP 200; MinerU API version upgrade changed the response schema; wrong endpoint path hitting a UI route that returns HTML.","solutions":["Log a truncated respBody with the error to see the actual payload received.","Verify c.endpoint points at the MinerU API base (…/file_parse), not a UI or proxy route.","Check the MinerU version's API docs and update the envelope struct to match the current schema.","Since a missing 'results' key unmarshals as empty (no error), also confirm status 200 is checked before decoding."],"exampleFix":"// before\nvar envelope struct {\n    Results map[string]mineruFileEntry `json:\"results\"`\n}\nif err := json.Unmarshal(respBody, &envelope); err != nil {\n    return \"\", nil, \"\", fmt.Errorf(\"decode response: %w\", err)\n}\n// after\nvar envelope struct {\n    Results map[string]mineruFileEntry `json:\"results\"`\n}\nif err := json.Unmarshal(respBody, &envelope); err != nil {\n    return \"\", nil, \"\", fmt.Errorf(\"decode response (%d bytes, head=%q): %w\", len(respBody), respBody[:min(200, len(respBody))], err)\n}","handlingStrategy":"validation","validationCode":"if !json.Valid(respBody) {\n    return fmt.Errorf(\"mineru returned non-JSON body (%d bytes)\", len(respBody))\n}","typeGuard":"func hasMinerUResults(body []byte) bool {\n    var probe struct {\n        Results map[string]json.RawMessage `json:\"results\"`\n    }\n    return json.Unmarshal(body, &probe) == nil\n}","tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"decode response\") {\n    // log payload head; treat as contract mismatch, do not retry\n    log.Printf(\"mineru response not parseable: %v\", err)\n}","preventionTips":["Log a truncated response body whenever decoding fails","Contract-test against the exact MinerU version in production","Verify HTTP 200 before attempting to decode","Detect HTML/proxy error pages early (check Content-Type header)"],"tags":["json","response-parsing","mineru","schema-mismatch"],"backgroundTag":"json-decode-failed","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}