{"record":{"id":"b77620bb34326718","repo":"thanos-io/thanos","slug":"decode-result-into-valuetypescalar","errorCode":null,"errorMessage":"decode result into ValueTypeScalar","messagePattern":"decode result into ValueTypeScalar","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/promclient/promclient.go","lineNumber":490,"sourceCode":"\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}\n\n// PromqlQueryInstant performs instant query and returns results in promql.Vector type that is compatible with promql package.\nfunc (c *Client) PromqlQueryInstant(ctx context.Context, base *url.URL, query string, t time.Time, opts QueryOptions) (promql.Vector, []string, error) {\n\tvectorResult, warnings, _, err := c.QueryInstant(ctx, base, query, t, opts)\n\tif err != nil {","sourceCodeStart":472,"sourceCodeEnd":508,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/promclient/promclient.go#L472-L508","documentation":"This error is thrown when Prometheus answered an instant query with resultType 'scalar' but convertScalarJSONToVector fails to decode the scalar result (a [timestamp, string-value] pair) into a model.Vector. It means the scalar payload is malformed — typically the timestamp or value element is missing or not in the expected format.","triggerScenarios":"PromqlQueryInstant returns a scalar query (e.g. 'count(up)' or a plain number expression) whose Result JSON is not a two-element [ts, value] array, or whose value string is not a valid float, or whose timestamp is not parseable.","commonSituations":"Third-party or proxied PromQL-compatible APIs returning differently shaped scalar results; mocked test fixtures with wrong scalar shape; backend bug or truncation of the response; unusual numeric formats (NaN/Inf encodings) the decoder rejects.","solutions":["Log m.Data.Result to inspect the actual scalar JSON and compare with the expected [timestamp, \"value\"] array","Validate the value string parses as a float (strconv.ParseFloat) on the backend side","Confirm the backend serializes scalars exactly like Prometheus ('result':[1710000000,\"42\"])","Check for response truncation through proxies/load balancers","Fix test fixtures to use the correct two-element scalar array"],"exampleFix":"// before (malformed scalar fixture)\n{\"status\":\"success\",\"data\":{\"resultType\":\"scalar\",\"result\":{\"value\":\"42\"}}}\n// after (correct scalar shape)\n{\"status\":\"success\",\"data\":{\"resultType\":\"scalar\",\"result\":[1710000000,\"42\"]}}","handlingStrategy":"validation","validationCode":"func validScalarResult(raw json.RawMessage) bool {\n    var pair []json.RawMessage\n    if err := json.Unmarshal(raw, &pair); err != nil || len(pair) != 2 {\n        return false\n    }\n    var val string\n    return json.Unmarshal(pair[1], &val) == nil\n}\n// call before trusting the scalar decode","typeGuard":"func isScalarShape(raw json.RawMessage) bool {\n    var pair [2]json.RawMessage\n    return json.Unmarshal(raw, &pair) == nil && len(pair) == 2\n}","tryCatchPattern":null,"preventionTips":["Ensure scalar fixtures are [timestamp, \"value-string\"] arrays","Check backend serializes values as strings, not raw numbers","Watch for NaN/Inf encodings your decoder may reject","Log raw Result JSON on scalar decode failures"],"tags":["json","prometheus","scalar","decode"],"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"}