thanos-io/thanos · error

decode result into ValueTypeScalar

Error message

decode result into ValueTypeScalar

What it means

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.

Solutions

  1. Log m.Data.Result to inspect the actual scalar JSON and compare with the expected [timestamp, "value"] array
  2. Validate the value string parses as a float (strconv.ParseFloat) on the backend side
  3. Confirm the backend serializes scalars exactly like Prometheus ('result':[1710000000,"42"])
  4. Check for response truncation through proxies/load balancers
  5. Fix test fixtures to use the correct two-element scalar array

Example fix

// before (malformed scalar fixture)
{"status":"success","data":{"resultType":"scalar","result":{"value":"42"}}}
// after (correct scalar shape)
{"status":"success","data":{"resultType":"scalar","result":[1710000000,"42"]}}
Defensive patterns

Strategy: validation

Validate before calling

func validScalarResult(raw json.RawMessage) bool {
    var pair []json.RawMessage
    if err := json.Unmarshal(raw, &pair); err != nil || len(pair) != 2 {
        return false
    }
    var val string
    return json.Unmarshal(pair[1], &val) == nil
}
// call before trusting the scalar decode

Type guard

func isScalarShape(raw json.RawMessage) bool {
    var pair [2]json.RawMessage
    return json.Unmarshal(raw, &pair) == nil && len(pair) == 2
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of thanos-io/thanos@35b8b99117 (2026-09-07). Data as JSON: /api/errors/b77620bb34326718. Report an issue: GitHub.

Appendix: source

Thrown at pkg/promclient/promclient.go:490

	}

	if err = json.Unmarshal(body, &m); err != nil {
		return nil, nil, nil, errors.Wrap(err, "unmarshal query instant response")
	}

	var vectorResult model.Vector

	// Decode the Result depending on the ResultType
	// Currently only `vector` and `scalar` types are supported.
	switch m.Data.ResultType {
	case string(parser.ValueTypeVector):
		if err = json.Unmarshal(m.Data.Result, &vectorResult); err != nil {
			return nil, nil, nil, errors.Wrap(err, "decode result into ValueTypeVector")
		}
	case string(parser.ValueTypeScalar):
		vectorResult, err = convertScalarJSONToVector(m.Data.Result)
		if err != nil {
			return nil, nil, nil, errors.Wrap(err, "decode result into ValueTypeScalar")
		}
	default:
		if m.Warnings != nil {
			return nil, nil, nil, errors.Errorf("error: %s, type: %s, warning: %s", m.Error, m.ErrorType, strings.Join(m.Warnings, ", "))
		}
		if m.Error != "" {
			return nil, nil, nil, errors.Errorf("error: %s, type: %s", m.Error, m.ErrorType)
		}
		return nil, nil, nil, errors.Errorf("received status code: 200, unknown response type: '%q'", m.Data.ResultType)
	}

	return vectorResult, m.Warnings, m.Data.Explanation, nil
}

// PromqlQueryInstant performs instant query and returns results in promql.Vector type that is compatible with promql package.
func (c *Client) PromqlQueryInstant(ctx context.Context, base *url.URL, query string, t time.Time, opts QueryOptions) (promql.Vector, []string, error) {
	vectorResult, warnings, _, err := c.QueryInstant(ctx, base, query, t, opts)
	if err != nil {

View on GitHub (pinned to 35b8b99117)