{"record":{"id":"b75c2a6014d0422e","repo":"thanos-io/thanos","slug":"unmarshal-query-instant-response","errorCode":null,"errorMessage":"unmarshal query instant response","messagePattern":"unmarshal query instant response","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/promclient/promclient.go","lineNumber":475,"sourceCode":"\t}\n\n\t// Decode only ResultType and load Result only as RawJson since we don't know\n\t// structure of the Result yet.\n\tvar m struct {\n\t\tData struct {\n\t\t\tResultType  string          `json:\"resultType\"`\n\t\t\tResult      json.RawMessage `json:\"result\"`\n\t\t\tExplanation *Explanation    `json:\"explanation,omitempty\"`\n\t\t} `json:\"data\"`\n\n\t\tError     string `json:\"error,omitempty\"`\n\t\tErrorType string `json:\"errorType,omitempty\"`\n\t\t// Extra fields supported by Thanos Querier.\n\t\tWarnings []string `json:\"warnings\"`\n\t}\n\n\tif err = json.Unmarshal(body, &m); err != nil {\n\t\treturn nil, nil, nil, errors.Wrap(err, \"unmarshal query instant response\")\n\t}\n\n\tvar vectorResult model.Vector\n\n\t// Decode the Result depending on the ResultType\n\t// Currently only `vector` and `scalar` types are supported.\n\tswitch m.Data.ResultType {\n\tcase string(parser.ValueTypeVector):\n\t\tif err = json.Unmarshal(m.Data.Result, &vectorResult); err != nil {\n\t\t\treturn nil, nil, nil, errors.Wrap(err, \"decode result into ValueTypeVector\")\n\t\t}\n\tcase string(parser.ValueTypeScalar):\n\t\tvectorResult, err = convertScalarJSONToVector(m.Data.Result)\n\t\tif err != nil {\n\t\t\treturn nil, nil, nil, errors.Wrap(err, \"decode result into ValueTypeScalar\")\n\t\t}\n\tdefault:\n\t\tif m.Warnings != nil {","sourceCodeStart":457,"sourceCodeEnd":493,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/promclient/promclient.go#L457-L493","documentation":"This error is thrown when the HTTP 200 body returned by Prometheus for an instant query cannot be parsed as JSON. QueryInstant unmarshals the response into a struct with Data, ResultType, Error, ErrorType and Warnings fields; a body that is not valid JSON (or wrong Content-Type, e.g. an HTML error page) makes json.Unmarshal fail. It signals the server replied 2xx but with a body that is not the expected API JSON envelope.","triggerScenarios":"PromqlQueryInstant receives a 200 response whose body is not valid JSON: an HTML login/proxy page, a truncated response, wrong Content-Type from a misconfigured proxy, or the endpoint returning plaintext (e.g. targeting the UI page instead of /api/v1/query).","commonSituations":"Reverse proxy or auth gateway returning an HTML page with 200; pointing the client at the Prometheus web UI root instead of the API path; custom middleware modifying the response body; Prometheus behind a gateway that strips or corrupts the payload.","solutions":["Verify the URL targets the JSON API path (/api/v1/query), not the web UI or a redirect target","curl the same query and inspect the Content-Type and raw body (expect application/json)","Check any proxy/gateway/auth layer is not injecting HTML pages with status 200","Confirm the server is actually Prometheus exposing the v1 query API","Log the raw body on this error to diagnose exactly what was returned"],"exampleFix":"// before\nresp, err := http.Get(\"https://prometheus.example.com/\") // returns HTML page -> unmarshal query instant response\n// after\nresp, err := http.Get(\"https://prometheus.example.com/api/v1/query?query=up\")","handlingStrategy":"try-catch","validationCode":"// preflight: confirm the endpoint returns JSON\nresp, err := http.Get(baseURL + \"/api/v1/query?query=up\")\nif err != nil { return err }\nif ct := resp.Header.Get(\"Content-Type\"); !strings.Contains(ct, \"application/json\") {\n    return fmt.Errorf(\"endpoint returned %q, not JSON\", ct)\n}","typeGuard":null,"tryCatchPattern":"_, _, _, err := client.PromqlQueryInstant(ctx, opts)\nvar perr *json.SyntaxError\nif err != nil && errors.As(errors.Cause(err), &perr) {\n    return fmt.Errorf(\"non-JSON response body at offset %d; check proxy/UI URL\", perr.Offset)\n}","preventionTips":["Point the client at /api/v1 endpoints, not the web UI root","Inspect Content-Type on a preflight request","Verify proxies/auth gateways do not return HTML with status 200","Log the raw body when unmarshal errors occur"],"tags":["json","prometheus","http","unmarshal"],"backgroundTag":"json-unmarshal-failed","analyzedSha":"35b8b991177def87ed52dcf10f9b6d87f07282c8","analyzedAt":"2026-09-07T01:49:59.689Z","contentChangedAt":"2026-09-07T01:49:59.689Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}