thanos-io/thanos · error

error parsing selector flag

Error message

error parsing selector flag

What it means

The bucket tools commands parse the --selector (relabel) flag with parseFlagLabels, which expects a comma-separated list of key="value" label pairs that must compile as valid Prometheus relabel matchers. This error wraps the underlying parse failure, meaning the selector flag value is malformed.

Solutions

  1. Quote each value: --selector='cluster="one",env="prod"' and verify shell quoting with `echo` first.
  2. Ensure every pair is key="value" with non-empty key and value.
  3. Check the wrapped inner error — it names the first offending label pair.
  4. If you intended regex matchers, use the flags that accept matchers (--match=...) rather than --selector.

Example fix

// before
thanos tools bucket verify --objstore.config-file=b.yml --selector=cluster=us-east
// after
thanos tools bucket verify --objstore.config-file=b.yml --selector='cluster="us-east"'
Defensive patterns

Strategy: validation

Validate before calling

for _, pair := range strings.Split(selectorFlag, ",") {
    parts := strings.SplitN(pair, "=", 2)
    if len(parts) != 2 || parts[0] == "" || !strings.HasPrefix(parts[1], "\"") {
        return fmt.Errorf("selector %q must be key=\"value\"", pair)
    }
}

Try / catch

if err := runBucketTool(); err != nil {
    if strings.Contains(err.Error(), "error parsing selector flag") {
        fmt.Fprintf(os.Stderr, "selector must be like --selector='key=\"value\"': %v\n", err)
        os.Exit(2)
    }
}

Prevention

When it happens

Trigger: Running any `thanos tools bucket` subcommand with --selector values that are not valid `key="value"` pairs — e.g. unquoted values, empty key, or invalid regex in the value — at cmd/thanos/tools_bucket.go:545.

Common situations: Shell quoting stripping the quotes (`--selector=cluster=one` instead of `--selector='cluster="one"'`), using label-matchers syntax where relabel format is required, or typos like trailing commas.

Understand the failure class

Background: "Unknown argument", "Invalid value", and "must be one of": invalid CLI argument errors explained — this error's family across 35 libraries.

Related errors


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

Appendix: source

Thrown at cmd/thanos/tools_bucket.go:545

		level.Info(logger).Log("msg", "ls done", "objects", objects)
		return nil
	})
}

func registerBucketInspect(app extkingpin.AppClause, objStoreConfig *extflag.PathOrContent) {
	cmd := app.Command("inspect", "Inspect all blocks in the bucket in detailed, table-like way.")

	tbc := &bucketInspectConfig{}
	tbc.registerBucketInspectFlag(cmd)

	output := cmd.Flag("output", "Output format for result. Currently supports table, csv, tsv.").Default("table").Enum(outputTypes...)

	cmd.Setup(func(g *run.Group, logger log.Logger, reg *prometheus.Registry, _ opentracing.Tracer, _ <-chan struct{}, _ bool) error {

		// Parse selector.
		selectorLabels, err := parseFlagLabels(tbc.selector)
		if err != nil {
			return errors.Wrap(err, "error parsing selector flag")
		}

		confContentYaml, err := objStoreConfig.Content()
		if err != nil {
			return err
		}

		bkt, err := client.NewBucket(logger, confContentYaml, component.Bucket.String(), nil)
		if err != nil {
			return err
		}
		insBkt := objstoretracing.WrapWithTraces(objstore.WrapWithMetrics(bkt, extprom.WrapRegistererWithPrefix("thanos_", reg), bkt.Name()))

		baseBlockIDsFetcher := block.NewConcurrentLister(logger, insBkt)
		fetcher, err := block.NewMetaFetcher(logger, block.FetcherConcurrency, insBkt, baseBlockIDsFetcher, "", extprom.WrapRegistererWithPrefix(extpromPrefix, reg), nil)
		if err != nil {
			return err
		}

View on GitHub (pinned to 35b8b99117)