{"record":{"id":"fc6383b3ae927148","repo":"thanos-io/thanos","slug":"error-s-type-s","errorCode":null,"errorMessage":"error: %s, type: %s","messagePattern":"error: (.+?), type: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/promclient/promclient.go","lineNumber":497,"sourceCode":"\n\t// Decode the Result depending on the ResultType\n\t// Currently only `vector` and `scalar` types are supported.\n\tswitch m.Data.ResultType {\n\tcase string(parser.ValueTypeVector):\n\t\tif err = json.Unmarshal(m.Data.Result, &vectorResult); err != nil {\n\t\t\treturn nil, nil, nil, errors.Wrap(err, \"decode result into ValueTypeVector\")\n\t\t}\n\tcase string(parser.ValueTypeScalar):\n\t\tvectorResult, err = convertScalarJSONToVector(m.Data.Result)\n\t\tif err != nil {\n\t\t\treturn nil, nil, nil, errors.Wrap(err, \"decode result into ValueTypeScalar\")\n\t\t}\n\tdefault:\n\t\tif m.Warnings != nil {\n\t\t\treturn nil, nil, nil, errors.Errorf(\"error: %s, type: %s, warning: %s\", m.Error, m.ErrorType, strings.Join(m.Warnings, \", \"))\n\t\t}\n\t\tif m.Error != \"\" {\n\t\t\treturn nil, nil, nil, errors.Errorf(\"error: %s, type: %s\", m.Error, m.ErrorType)\n\t\t}\n\t\treturn nil, nil, nil, errors.Errorf(\"received status code: 200, unknown response type: '%q'\", m.Data.ResultType)\n\t}\n\n\treturn vectorResult, m.Warnings, m.Data.Explanation, nil\n}\n\n// PromqlQueryInstant performs instant query and returns results in promql.Vector type that is compatible with promql package.\nfunc (c *Client) PromqlQueryInstant(ctx context.Context, base *url.URL, query string, t time.Time, opts QueryOptions) (promql.Vector, []string, error) {\n\tvectorResult, warnings, _, err := c.QueryInstant(ctx, base, query, t, opts)\n\tif err != nil {\n\t\treturn nil, nil, err\n\t}\n\n\tvec := make(promql.Vector, 0, len(vectorResult))\n\n\tb := labels.NewScratchBuilder(0)\n\tfor _, e := range vectorResult {","sourceCodeStart":479,"sourceCodeEnd":515,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/promclient/promclient.go#L479-L515","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["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.","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.","Ensure the client and server are version-compatible; if a new result type was introduced upstream, update the promclient to handle it.","If warnings accompany the error, inspect the 'warning:' section of the message for hints about partial data or store issues."],"exampleFix":"// before\nresult, warnings, _, err := api.PromqlQueryInstant(ctx, \"up{job=~\\\".*\\\"}\", ts)\n// after\nif !strings.Contains(q, \"=\") && !strings.Contains(q, \"up\") { /* validate selectors */ }\nresult, warnings, _, err := api.PromqlQueryInstant(ctx, \"up{job=\\\"prometheus\\\"}\", ts)\nif err != nil {\n    var perr *promclient.QueryError\n    if errors.As(err, &perr) { /* inspect perr.ErrorType before retrying */ }\n}","handlingStrategy":"try-catch","validationCode":"// Validate PromQL locally before issuing an instant query\nif q == \"\" || strings.Count(q, \"{\") != strings.Count(q, \"}\") {\n    return fmt.Errorf(\"invalid promql query: %q\", q)\n}\n// optionally use promql parser:\n// if _, err := parser.ParseExpr(q); err != nil { return err }","typeGuard":"func isPrometheusQueryError(err error) bool {\n    return err != nil && strings.Contains(err.Error(), \"error: \")\n}","tryCatchPattern":"result, warnings, expl, err := api.PromqlQueryInstant(ctx, q, ts)\nif err != nil {\n    // message embeds upstream prom error and type: 'error: %s, type: %s'\n    log.Errorf(\"instant query failed: %v\", err)\n    return fmt.Errorf(\"promql instant query %q failed: %w\", q, err)\n}","preventionTips":["Parse/validate PromQL with the promql parser before sending","Avoid unbounded regex matchers and overly wide selectors","Keep client and server versions aligned","Inspect ErrorType in the message to categorize failures (bad_data vs timeout vs execution)"],"tags":["prometheus","promql","query","upstream-error"],"backgroundTag":"api-error-response","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"}