{"record":{"id":"768b5516fd5f6c23","repo":"thanos-io/thanos","slug":"decode-result-into-valuetypevector","errorCode":null,"errorMessage":"decode result into ValueTypeVector","messagePattern":"decode result into ValueTypeVector","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/promclient/promclient.go","lineNumber":485,"sourceCode":"\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 {\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\t\treturn nil, nil, nil, errors.Errorf(\"received status code: 200, unknown response type: '%q'\", m.Data.ResultType)\n\t}\n\n\treturn vectorResult, m.Warnings, m.Data.Explanation, nil\n}","sourceCodeStart":467,"sourceCodeEnd":503,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/promclient/promclient.go#L467-L503","documentation":"This error is thrown when Prometheus answered an instant query with resultType 'vector' but the Result payload fails to unmarshal into a model.Vector (a slice of samples with metric labels, timestamp and value). It means the JSON structure of individual result entries does not match what the Prometheus model expects — an unexpected or malformed payload despite a nominally successful query.","triggerScenarios":"PromqlQueryInstant gets resultType 'vector' but the Result array contains entries with unexpected fields/types: non-numeric 'value' fields, missing metric/value arrays, or a server (e.g. an unusual Prometheus-compatible backend) emitting a slightly different vector schema.","commonSituations":"Pointing the client at a Prometheus-compatible system (e.g. a custom or third-party TSDB API) that serializes vectors differently; corrupted/proxied response bodies; major Prometheus model version drift; hand-rolled mock servers in tests with wrong sample shapes.","solutions":["Log m.Data.Result (the raw JSON) when this error occurs to compare against the expected vector schema [ {metric, value:[ts, \"val\"]} ]","Confirm the backend is standard Prometheus/vmalert-compatible and its API version matches the library's promclient expectations","Check for proxies/middleware rewriting the response body","Upgrade or pin the client library to match the server's API version","If testing, fix mock fixtures to emit proper vector sample JSON"],"exampleFix":"// before (malformed fixture in a test server)\n{\"status\":\"success\",\"data\":{\"resultType\":\"vector\",\"result\":[{\"metric\":{\"__name__\":\"up\"},\"value\":1}]}}\n// after (correct vector sample shape)\n{\"status\":\"success\",\"data\":{\"resultType\":\"vector\",\"result\":[{\"metric\":{\"__name__\":\"up\"},\"value\":[1710000000,\"1\"]}]}}","handlingStrategy":"validation","validationCode":"// verify your backend's vector response shape before parsing\ntype vectorSample struct {\n    Metric map[string]string `json:\"metric\"`\n    Value  []interface{}     `json:\"value\"`\n}\nfunc validVectorResult(raw json.RawMessage) bool {\n    var samples []vectorSample\n    if err := json.Unmarshal(raw, &samples); err != nil {\n        return false\n    }\n    for _, s := range samples {\n        if len(s.Value) != 2 { return false }\n        if _, ok := s.Value[1].(string); !ok { return false }\n    }\n    return true\n}","typeGuard":"func isVectorShape(raw json.RawMessage) bool {\n    var v []struct{ Value []json.RawMessage `json:\"value\"` } `json:\"result\"`\n    return json.Unmarshal(raw, &v) == nil && len(v) >= 0\n}","tryCatchPattern":null,"preventionTips":["Test against the exact Prometheus version you deploy","Keep mock fixtures in the canonical shape {metric, value:[ts,\"val\"]}","Compare raw m.Data.Result with expected schema when decode fails","Avoid non-standard Prometheus-compatible backends or verify their output"],"tags":["json","prometheus","decode","response-shape"],"backgroundTag":"unexpected-response-shape","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"}