thanos-io/thanos · error
invalid scalar result format
Error message
invalid scalar result format %v, expected timestamp -> value tuple
What it means
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.
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).
Example fix
// before: malformed scalar result "result": [] // after: valid scalar tuple "result": [1710000000000, "42"]
Defensive patterns
Strategy: validation
Validate before calling
// when feeding JSON directly (tests/mocks), check shape first
var raw []json.RawMessage
json.Unmarshal(scalarJSON, &raw)
if len(raw) != 2 {
return errors.New("scalar result must be a 2-element [timestamp, value] tuple")
} Try / catch
v, err := convertScalarJSONToVector(raw)
if err != nil {
// log raw result JSON; fix server/fixture to emit [ts, "value"]
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: Nonstandard server implementations or mocks returning malformed scalar results; response rewriting middleware; tests feeding hand-crafted JSON with the wrong shape.
Related errors
- fetch Prometheus flags
- validate relabel config
- decode result into ValueTypeScalar
- unmarshaling scalar time from
- unmarshaling scalar value from
AI-assisted analysis of thanos-io/thanos@35b8b99117 (2026-09-07).
Data as JSON: /api/errors/7b16ab1720336ef8.
Report an issue: GitHub.
Appendix: source
Thrown at pkg/promclient/promclient.go:618
}
return matrixResult, m.Warnings, m.Data.Explanation, nil
}
// Scalar response consists of array with mixed types so it needs to be
// unmarshaled separately.
func convertScalarJSONToVector(scalarJSONResult json.RawMessage) (model.Vector, error) {
var (
// Do not specify exact length of the expected slice since JSON unmarshaling
// would make the length fit the size and we won't be able to check the length afterwards.
resultPointSlice []json.RawMessage
resultTime model.Time
resultValue model.SampleValue
)
if err := json.Unmarshal(scalarJSONResult, &resultPointSlice); err != nil {
return nil, err
}
if len(resultPointSlice) != 2 {
return nil, errors.Errorf("invalid scalar result format %v, expected timestamp -> value tuple", resultPointSlice)
}
if err := json.Unmarshal(resultPointSlice[0], &resultTime); err != nil {
return nil, errors.Wrapf(err, "unmarshaling scalar time from %v", resultPointSlice)
}
if err := json.Unmarshal(resultPointSlice[1], &resultValue); err != nil {
return nil, errors.Wrapf(err, "unmarshaling scalar value from %v", resultPointSlice)
}
return model.Vector{&model.Sample{
Metric: model.Metric{},
Value: resultValue,
Timestamp: resultTime}}, nil
}
// AlertmanagerAlerts returns alerts from Alertmanager.
func (c *Client) AlertmanagerAlerts(ctx context.Context, base *url.URL) ([]*model.Alert, error) {
u := *base
u.Path = path.Join(u.Path, "/api/v1/alerts")
View on GitHub (pinned to 35b8b99117)