{"record":{"id":"77c04d4de500d770","repo":"thanos-io/thanos","slug":"decode-result-into-valuetypematrix","errorCode":null,"errorMessage":"decode result into ValueTypeMatrix","messagePattern":"decode result into ValueTypeMatrix","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/promclient/promclient.go","lineNumber":589,"sourceCode":"\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 range response\")\n\t}\n\n\tvar matrixResult model.Matrix\n\n\t// Decode the Result depending on the ResultType\n\tswitch m.Data.ResultType {\n\tcase string(parser.ValueTypeMatrix):\n\t\tif err = json.Unmarshal(m.Data.Result, &matrixResult); err != nil {\n\t\t\treturn nil, nil, nil, errors.Wrap(err, \"decode result into ValueTypeMatrix\")\n\t\t}\n\tdefault:\n\t\tif m.Warnings != nil {\n\t\t\treturn nil, nil, nil, errors.Errorf(\"error: %s, type: %s, warning: %s\", m.Error, m.ErrorType, strings.Join(m.Warnings, \", \"))\n\t\t}\n\t\tif m.Error != \"\" {\n\t\t\treturn nil, nil, nil, errors.Errorf(\"error: %s, type: %s\", m.Error, m.ErrorType)\n\t\t}\n\n\t\treturn nil, nil, nil, errors.Errorf(\"received status code: 200, unknown response type: '%q'\", m.Data.ResultType)\n\t}\n\treturn matrixResult, m.Warnings, m.Data.Explanation, nil\n}\n\n// Scalar response consists of array with mixed types so it needs to be\n// unmarshaled separately.\nfunc convertScalarJSONToVector(scalarJSONResult json.RawMessage) (model.Vector, error) {\n\tvar (","sourceCodeStart":571,"sourceCodeEnd":607,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/promclient/promclient.go#L571-L607","documentation":"After the envelope decodes, QueryRange sees data.resultType == \"matrix\" and unmarshals data.result into prometheus/common's model.Matrix. This error wraps a failure to decode the raw result JSON into that type — the samples/series inside data.result do not match the expected matrix JSON structure (arrays of {metric, values} objects).","triggerScenarios":"QueryRange (via Exec) receives a 200 response whose resultType is \"matrix\" but whose result payload cannot decode into model.Matrix — e.g. values arrays containing non-numeric strings, malformed sample pairs, or a nonstandard result emitted by a proxy/modified server.","commonSituations":"A third-party or older server claiming resultType matrix but emitting differently shaped samples; a caching proxy serving a corrupted/cached body; custom Prometheus forks or response-rewriting middleware.","solutions":["Log m.Data.Result (raw JSON) at the call site to inspect the actual sample structure.","Confirm the server is genuine Prometheus/Thanos and check its version; upgrade if a known result-encoding bug exists.","Check for response-rewriting middleware or caches in the path and bypass them to test directly.","Validate the query itself does not hit a federated/gateway layer that reformats results."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"decode result into ValueTypeMatrix\") {\n    // capture raw result for debugging; suspect server/middleware corruption\n}","preventionTips":["Use stock Prometheus/Thanos servers; avoid response-rewriting middleware","Pin and test server versions in CI","Log raw result payloads on failure for post-mortem"],"tags":["json","prometheus","matrix","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"}