{"record":{"id":"38ed0ba26085a737","repo":"thanos-io/thanos","slug":"error-parsing-selector-flag","errorCode":null,"errorMessage":"error parsing selector flag","messagePattern":"error parsing selector flag","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/thanos/tools_bucket.go","lineNumber":545,"sourceCode":"\t\tlevel.Info(logger).Log(\"msg\", \"ls done\", \"objects\", objects)\n\t\treturn nil\n\t})\n}\n\nfunc registerBucketInspect(app extkingpin.AppClause, objStoreConfig *extflag.PathOrContent) {\n\tcmd := app.Command(\"inspect\", \"Inspect all blocks in the bucket in detailed, table-like way.\")\n\n\ttbc := &bucketInspectConfig{}\n\ttbc.registerBucketInspectFlag(cmd)\n\n\toutput := cmd.Flag(\"output\", \"Output format for result. Currently supports table, csv, tsv.\").Default(\"table\").Enum(outputTypes...)\n\n\tcmd.Setup(func(g *run.Group, logger log.Logger, reg *prometheus.Registry, _ opentracing.Tracer, _ <-chan struct{}, _ bool) error {\n\n\t\t// Parse selector.\n\t\tselectorLabels, err := parseFlagLabels(tbc.selector)\n\t\tif err != nil {\n\t\t\treturn errors.Wrap(err, \"error parsing selector flag\")\n\t\t}\n\n\t\tconfContentYaml, err := objStoreConfig.Content()\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\tbkt, err := client.NewBucket(logger, confContentYaml, component.Bucket.String(), nil)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tinsBkt := objstoretracing.WrapWithTraces(objstore.WrapWithMetrics(bkt, extprom.WrapRegistererWithPrefix(\"thanos_\", reg), bkt.Name()))\n\n\t\tbaseBlockIDsFetcher := block.NewConcurrentLister(logger, insBkt)\n\t\tfetcher, err := block.NewMetaFetcher(logger, block.FetcherConcurrency, insBkt, baseBlockIDsFetcher, \"\", extprom.WrapRegistererWithPrefix(extpromPrefix, reg), nil)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}","sourceCodeStart":527,"sourceCodeEnd":563,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/cmd/thanos/tools_bucket.go#L527-L563","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Quote each value: --selector='cluster=\"one\",env=\"prod\"' and verify shell quoting with `echo` first.","Ensure every pair is key=\"value\" with non-empty key and value.","Check the wrapped inner error — it names the first offending label pair.","If you intended regex matchers, use the flags that accept matchers (--match=...) rather than --selector."],"exampleFix":"// before\nthanos tools bucket verify --objstore.config-file=b.yml --selector=cluster=us-east\n// after\nthanos tools bucket verify --objstore.config-file=b.yml --selector='cluster=\"us-east\"'","handlingStrategy":"validation","validationCode":"for _, pair := range strings.Split(selectorFlag, \",\") {\n    parts := strings.SplitN(pair, \"=\", 2)\n    if len(parts) != 2 || parts[0] == \"\" || !strings.HasPrefix(parts[1], \"\\\"\") {\n        return fmt.Errorf(\"selector %q must be key=\\\"value\\\"\", pair)\n    }\n}","typeGuard":null,"tryCatchPattern":"if err := runBucketTool(); err != nil {\n    if strings.Contains(err.Error(), \"error parsing selector flag\") {\n        fmt.Fprintf(os.Stderr, \"selector must be like --selector='key=\\\"value\\\"': %v\\n\", err)\n        os.Exit(2)\n    }\n}","preventionTips":["Always single-quote the whole --selector value in shell","Use key=\"value\" pairs with inner double quotes","Echo the expanded command to verify quoting before running","Use --match flags when you need regex matchers instead"],"tags":["cli","labels","flag-parsing"],"backgroundTag":"invalid-cli-argument","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"}