{"record":{"id":"ccbdbce82c9e92cb","repo":"thanos-io/thanos","slug":"unable-to-parse-external-labels","errorCode":null,"errorMessage":"unable to parse external labels","messagePattern":"unable to parse external labels","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/thanos/tools_bucket.go","lineNumber":1470,"sourceCode":"\t\t}\n\t\treturn nil\n\t})\n}\n\nfunc registerBucketUploadBlocks(app extkingpin.AppClause, objStoreConfig *extflag.PathOrContent) {\n\tcmd := app.Command(\"upload-blocks\", \"Upload blocks push blocks from the provided path to the object storage.\")\n\n\ttbc := &bucketUploadBlocksConfig{}\n\ttbc.registerBucketUploadBlocksFlag(cmd)\n\n\tcmd.Setup(func(g *run.Group, logger log.Logger, reg *prometheus.Registry, _ opentracing.Tracer, _ <-chan struct{}, _ bool) error {\n\t\tif len(tbc.labels) == 0 {\n\t\t\treturn errors.New(\"no external labels configured, uniquely identifying external labels must be configured; see https://thanos.io/tip/thanos/storage.md#external-labels for details.\")\n\t\t}\n\n\t\tlset, err := parseFlagLabels(tbc.labels)\n\t\tif err != nil {\n\t\t\treturn errors.Wrap(err, \"unable to parse external labels\")\n\t\t}\n\t\tif err := promclient.IsDirAccessible(tbc.path); err != nil {\n\t\t\treturn errors.Wrapf(err, \"unable to access path '%s'\", tbc.path)\n\t\t}\n\n\t\tconfContentYaml, err := objStoreConfig.Content()\n\t\tif err != nil {\n\t\t\treturn errors.Wrap(err, \"unable to parse objstore config\")\n\t\t}\n\n\t\tbkt, err := client.NewBucket(logger, confContentYaml, component.Upload.String(), nil)\n\t\tif err != nil {\n\t\t\treturn errors.Wrap(err, \"unable to create bucket\")\n\t\t}\n\n\t\tbkt = objstoretracing.WrapWithTraces(objstore.WrapWithMetrics(bkt, extprom.WrapRegistererWithPrefix(\"thanos_\", reg), bkt.Name()))\n\n\t\ttbcDir, err := os.OpenRoot(tbc.path)","sourceCodeStart":1452,"sourceCodeEnd":1488,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/cmd/thanos/tools_bucket.go#L1452-L1488","documentation":"Wraps a failure from parseFlagLabels when the --label flags cannot be parsed into valid Prometheus labels. Labels must be key=\"value\" pairs with valid label-name and label-value characters; invalid syntax causes this wrapped error.","triggerScenarios":"Passing --label values that are not valid key=value pairs, contain invalid characters, duplicate keys, or wrong quoting (e.g. unquoted values with spaces, or '=' in the key).","commonSituations":"Shell quoting stripping double quotes so values contain spaces or bad chars, using invalid label names (starting with digits, special characters), or passing an empty --label flag.","solutions":["Check the wrapped error for the offending label and fix its syntax: --label key=\"value\".","Quote labels in the shell so values with special characters survive (single-quote the whole flag argument).","Ensure label names match [a-zA-Z_][a-zA-Z0-9_]* and values are valid UTF-8 label values.","Avoid duplicate keys across --label flags."],"exampleFix":"// before\n--label cluster=us-east 1        # space breaks parsing\n// after\n--label 'cluster=\"us-east-1\"'   # properly quoted key=\"value\"","handlingStrategy":"validation","validationCode":"// Go: validate label pairs before passing to the CLI\nfunc validLabel(l string) bool {\n    parts := strings.SplitN(l, \"=\", 2)\n    if len(parts) != 2 { return false }\n    return labels.IsValidName(parts[0]) && utf8.ValidString(parts[1])\n}","typeGuard":null,"tryCatchPattern":"if err := runUpload(labels); err != nil {\n    if strings.Contains(err.Error(), \"unable to parse external labels\") {\n        log.Fatalf(\"bad --label syntax, use --label key=\\\"value\\\" with valid label names: %v\", err)\n    }\n}","preventionTips":["Always single-quote --label arguments in shell so inner quotes survive.","Keep label names matching [a-zA-Z_][a-zA-Z0-9_]* and avoid spaces in values.","Reuse the exact label strings from the Prometheus external_labels config to avoid drift."],"tags":["cli","labels","parsing"],"backgroundTag":"invalid-argument-format","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"}