{"record":{"id":"2cc631819cdad518","repo":"thanos-io/thanos","slug":"add-thanos-opts-query-params","errorCode":null,"errorMessage":"add thanos opts query params","messagePattern":"add thanos opts query params","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/promclient/promclient.go","lineNumber":436,"sourceCode":"\treturn nil\n}\n\ntype Explanation struct {\n\tName     string         `json:\"name\"`\n\tChildren []*Explanation `json:\"children,omitempty\"`\n}\n\n// QueryInstant performs an instant query using a default HTTP client and returns results in model.Vector type.\nfunc (c *Client) QueryInstant(ctx context.Context, base *url.URL, query string, t time.Time, opts QueryOptions) (model.Vector, []string, *Explanation, error) {\n\tparams, err := url.ParseQuery(base.RawQuery)\n\tif err != nil {\n\t\treturn nil, nil, nil, errors.Wrapf(err, \"parse raw query %s\", base.RawQuery)\n\t}\n\tparams.Add(\"query\", query)\n\tparams.Add(\"time\", t.Format(time.RFC3339Nano))\n\tif !opts.DoNotAddThanosParams {\n\t\tif err := opts.AddTo(params); err != nil {\n\t\t\treturn nil, nil, nil, errors.Wrap(err, \"add thanos opts query params\")\n\t\t}\n\t}\n\n\tu := *base\n\tu.Path = path.Join(u.Path, \"/api/v1/query\")\n\tu.RawQuery = params.Encode()\n\n\tlevel.Debug(c.logger).Log(\"msg\", \"querying instant\", \"url\", u.String())\n\n\tspan, ctx := tracing.StartSpan(ctx, \"/prom_query_instant HTTP[client]\")\n\tdefer span.Finish()\n\n\tmethod := opts.Method\n\tif method == \"\" {\n\t\tmethod = http.MethodGet\n\t}\n\n\tbody, _, err := c.req2xx(ctx, &u, method, opts.HTTPHeaders)","sourceCodeStart":418,"sourceCodeEnd":454,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/promclient/promclient.go#L418-L454","documentation":"QueryInstant calls opts.AddTo(params) to append Thanos-specific parameters (partial_response etc.) to the parsed query. If AddTo rejects the options — which happens only for an unknown PartialResponseStrategy — it wraps the failure as 'add thanos opts query params'. See also error 'unknown partial response strategy %v' (657), which is the root cause.","triggerScenarios":"Calling QueryInstant with QueryOptions whose PartialResponseStrategy is neither WARN nor ABORT; the inner AddTo error is wrapped and re-raised by this message.","commonSituations":"Same root causes as the unknown-strategy error: zero-value enums from unvalidated config, enum type drift across Thanos versions, copying options between incompatible code paths.","solutions":["Pass storepb.PartialResponseStrategy_WARN or _ABORT explicitly in QueryOptions","Unwrap the chained error to confirm the unknown-strategy root cause","Validate strategy values at config-load time before they reach query code","Set DoNotAddThanosParams=true if querying vanilla Prometheus where Thanos params are unnecessary"],"exampleFix":"// before\nopts := promclient.QueryOptions{}\nvec, _, _, err := client.QueryInstant(ctx, base, `up`, time.Now(), opts)\n// after\nopts := promclient.QueryOptions{PartialResponseStrategy: storepb.PartialResponseStrategy_ABORT}\nvec, _, _, err := client.QueryInstant(ctx, base, `up`, time.Now(), opts)","handlingStrategy":"validation","validationCode":"if opts.PartialResponseStrategy != storepb.PartialResponseStrategy_WARN &&\n    opts.PartialResponseStrategy != storepb.PartialResponseStrategy_ABORT {\n    return fmt.Errorf(\"invalid strategy %v before query\", opts.PartialResponseStrategy)\n}","typeGuard":"func optsValid(o promclient.QueryOptions) bool {\n    return o.PartialResponseStrategy == storepb.PartialResponseStrategy_WARN ||\n        o.PartialResponseStrategy == storepb.PartialResponseStrategy_ABORT\n}","tryCatchPattern":"vec, _, _, err := client.QueryInstant(ctx, base, query, t, opts)\nif err != nil && strings.Contains(err.Error(), \"add thanos opts query params\") {\n    return fmt.Errorf(\"fix QueryOptions strategy: %w\", err)\n}","preventionTips":["Validate QueryOptions before every QueryInstant/QueryRange call","Set strategy explicitly at construction time","Set DoNotAddThanosParams=true for vanilla Prometheus targets"],"tags":["enum","query","thanos","wrapped-error"],"backgroundTag":"invalid-enum-value","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"}