thanos-io/thanos · error

decode result into ValueTypeVector

Error message

decode result into ValueTypeVector

What it means

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.

Solutions

  1. Log m.Data.Result (the raw JSON) when this error occurs to compare against the expected vector schema [ {metric, value:[ts, "val"]} ]
  2. Confirm the backend is standard Prometheus/vmalert-compatible and its API version matches the library's promclient expectations
  3. Check for proxies/middleware rewriting the response body
  4. Upgrade or pin the client library to match the server's API version
  5. If testing, fix mock fixtures to emit proper vector sample JSON

Example fix

// before (malformed fixture in a test server)
{"status":"success","data":{"resultType":"vector","result":[{"metric":{"__name__":"up"},"value":1}]}}
// after (correct vector sample shape)
{"status":"success","data":{"resultType":"vector","result":[{"metric":{"__name__":"up"},"value":[1710000000,"1"]}]}}
Defensive patterns

Strategy: validation

Validate before calling

// verify your backend's vector response shape before parsing
type vectorSample struct {
    Metric map[string]string `json:"metric"`
    Value  []interface{}     `json:"value"`
}
func validVectorResult(raw json.RawMessage) bool {
    var samples []vectorSample
    if err := json.Unmarshal(raw, &samples); err != nil {
        return false
    }
    for _, s := range samples {
        if len(s.Value) != 2 { return false }
        if _, ok := s.Value[1].(string); !ok { return false }
    }
    return true
}

Type guard

func isVectorShape(raw json.RawMessage) bool {
    var v []struct{ Value []json.RawMessage `json:"value"` } `json:"result"`
    return json.Unmarshal(raw, &v) == nil && len(v) >= 0
}

Prevention

When it happens

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

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

Related errors


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

Appendix: source

Thrown at pkg/promclient/promclient.go:485

		Error     string `json:"error,omitempty"`
		ErrorType string `json:"errorType,omitempty"`
		// Extra fields supported by Thanos Querier.
		Warnings []string `json:"warnings"`
	}

	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
}

View on GitHub (pinned to 35b8b99117)