thanos-io/thanos · error

error: , type

Error message

error: %s, type: %s

What it means

QueryInstant received a 200 OK from the Prometheus HTTP API, but the response body carried a Prometheus error (m.Error non-empty) or the result type was not one of the handled vector/matrix/scalar/string cases. The library wraps the upstream Prometheus error and its ErrorType (e.g. 'bad_data', 'timeout', 'execution') via errors.Errorf. This means the query itself failed server-side despite the HTTP request succeeding.

Solutions

  1. Fix the PromQL query so it evaluates successfully; run it directly against the Prometheus /api/v1/query endpoint to see the raw error message and type embedded in this error.
  2. Check the 'type:' portion of the message (m.ErrorType) — bad_data means syntax issues, timeout/execution means tune --query.timeout or narrow the query's time range and matchers.
  3. Ensure the client and server are version-compatible; if a new result type was introduced upstream, update the promclient to handle it.
  4. If warnings accompany the error, inspect the 'warning:' section of the message for hints about partial data or store issues.

Example fix

// before
result, warnings, _, err := api.PromqlQueryInstant(ctx, "up{job=~\".*\"}", ts)
// after
if !strings.Contains(q, "=") && !strings.Contains(q, "up") { /* validate selectors */ }
result, warnings, _, err := api.PromqlQueryInstant(ctx, "up{job=\"prometheus\"}", ts)
if err != nil {
    var perr *promclient.QueryError
    if errors.As(err, &perr) { /* inspect perr.ErrorType before retrying */ }
}
Defensive patterns

Strategy: try-catch

Validate before calling

// Validate PromQL locally before issuing an instant query
if q == "" || strings.Count(q, "{") != strings.Count(q, "}") {
    return fmt.Errorf("invalid promql query: %q", q)
}
// optionally use promql parser:
// if _, err := parser.ParseExpr(q); err != nil { return err }

Type guard

func isPrometheusQueryError(err error) bool {
    return err != nil && strings.Contains(err.Error(), "error: ")
}

Try / catch

result, warnings, expl, err := api.PromqlQueryInstant(ctx, q, ts)
if err != nil {
    // message embeds upstream prom error and type: 'error: %s, type: %s'
    log.Errorf("instant query failed: %v", err)
    return fmt.Errorf("promql instant query %q failed: %w", q, err)
}

Prevention

When it happens

Trigger: Calling PromqlQueryInstant/Client.QueryInstant with a query string that Prometheus rejects or fails to evaluate: syntactically invalid PromQL, unbounded regex matchers, timeouts, or store failures. Any instant query whose API response has m.Error != "" and falls into the default branch of the result-type switch.

Common situations: Typos in metric names or PromQL syntax, regex matchers matching too many series, exceeding the query timeout or max samples limit, Thanos/Sidecar store errors, or Prometheus versions returning a result type the client doesn't handle.

Related errors


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

Appendix: source

Thrown at pkg/promclient/promclient.go:497

	// 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 {
		return nil, nil, err
	}

	vec := make(promql.Vector, 0, len(vectorResult))

	b := labels.NewScratchBuilder(0)
	for _, e := range vectorResult {

View on GitHub (pinned to 35b8b99117)