{"record":{"id":"7b16ab1720336ef8","repo":"thanos-io/thanos","slug":"invalid-scalar-result-format-v-expected-timestam","errorCode":null,"errorMessage":"invalid scalar result format %v, expected timestamp -> value tuple","messagePattern":"invalid scalar result format (.+?), expected timestamp -> value tuple","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/promclient/promclient.go","lineNumber":618,"sourceCode":"\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 (\n\t\t// Do not specify exact length of the expected slice since JSON unmarshaling\n\t\t// would make the length fit the size and we won't be able to check the length afterwards.\n\t\tresultPointSlice []json.RawMessage\n\t\tresultTime       model.Time\n\t\tresultValue      model.SampleValue\n\t)\n\tif err := json.Unmarshal(scalarJSONResult, &resultPointSlice); err != nil {\n\t\treturn nil, err\n\t}\n\tif len(resultPointSlice) != 2 {\n\t\treturn nil, errors.Errorf(\"invalid scalar result format %v, expected timestamp -> value tuple\", resultPointSlice)\n\t}\n\tif err := json.Unmarshal(resultPointSlice[0], &resultTime); err != nil {\n\t\treturn nil, errors.Wrapf(err, \"unmarshaling scalar time from %v\", resultPointSlice)\n\t}\n\tif err := json.Unmarshal(resultPointSlice[1], &resultValue); err != nil {\n\t\treturn nil, errors.Wrapf(err, \"unmarshaling scalar value from %v\", resultPointSlice)\n\t}\n\treturn model.Vector{&model.Sample{\n\t\tMetric:    model.Metric{},\n\t\tValue:     resultValue,\n\t\tTimestamp: resultTime}}, nil\n}\n\n// AlertmanagerAlerts returns alerts from Alertmanager.\nfunc (c *Client) AlertmanagerAlerts(ctx context.Context, base *url.URL) ([]*model.Alert, error) {\n\tu := *base\n\tu.Path = path.Join(u.Path, \"/api/v1/alerts\")\n","sourceCodeStart":600,"sourceCodeEnd":636,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/promclient/promclient.go#L600-L636","documentation":"convertScalarJSONToVector decodes a scalar/string result, which Prometheus encodes as a two-element array [timestamp, value]. This error fires when the decoded JSON array does not have exactly two elements, so it cannot be interpreted as a timestamp -> value tuple. It is deliberately checked after unmarshaling into a slice without a fixed length so the length remains observable.","triggerScenarios":"Called from QueryInstant (or TestRule_UnmarshalScalarResponse) when data.result for a scalar response decodes to an array whose length != 2 — e.g. empty array, nested arrays, or an object where a tuple was expected.","commonSituations":"Nonstandard server implementations or mocks returning malformed scalar results; response rewriting middleware; tests feeding hand-crafted JSON with the wrong shape.","solutions":["Inspect the raw data.result JSON to see the actual shape returned.","Fix the server/mock/test fixture so scalar results are exactly [<unix_ts_ms>, \"<value>\"] as an array.","Remove any proxy/middleware that mutates the response payload.","If the server legitimately returns vector results, ensure the query/resultType handling matches (scalar vs vector paths)."],"exampleFix":"// before: malformed scalar result\n\"result\": []\n// after: valid scalar tuple\n\"result\": [1710000000000, \"42\"]","handlingStrategy":"validation","validationCode":"// when feeding JSON directly (tests/mocks), check shape first\nvar raw []json.RawMessage\njson.Unmarshal(scalarJSON, &raw)\nif len(raw) != 2 {\n    return errors.New(\"scalar result must be a 2-element [timestamp, value] tuple\")\n}","typeGuard":null,"tryCatchPattern":"v, err := convertScalarJSONToVector(raw)\nif err != nil {\n    // log raw result JSON; fix server/fixture to emit [ts, \"value\"]\n}","preventionTips":["Match Prometheus scalar format exactly: [unix_ms, \"value\"]","Keep mocks and test fixtures derived from real server captures","Avoid middleware that mutates API response payloads"],"tags":["prometheus","scalar","response-format","validation"],"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"}