{"record":{"id":"0d9a944bbc0e20d0","repo":"thanos-io/thanos","slug":"unquote-label-value","errorCode":null,"errorMessage":"unquote label value","messagePattern":"unquote label value","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/thanos/config.go","lineNumber":339,"sourceCode":"\tac.alertRelabelConfigPath = extflag.RegisterPathOrContent(cmd, \"alert.relabel-config\", \"YAML file that contains alert relabelling configuration.\", extflag.WithEnvSubstitution())\n\tac.alertSourceTemplate = cmd.Flag(\"alert.query-template\", \"Template to use in alerts source field. Need only include {{.Expr}} parameter\").Default(\"/graph?g0.expr={{.Expr}}&g0.tab=1\").String()\n\n\treturn ac\n}\n\nfunc parseFlagLabels(s []string) (labels.Labels, error) {\n\tvar lset labels.ScratchBuilder\n\tfor _, l := range s {\n\t\tparts := strings.SplitN(l, \"=\", 2)\n\t\tif len(parts) != 2 {\n\t\t\treturn labels.EmptyLabels(), errors.Errorf(\"unrecognized label %q\", l)\n\t\t}\n\t\tif !model.UTF8Validation.IsValidLabelName(parts[0]) {\n\t\t\treturn labels.EmptyLabels(), errors.Errorf(\"unsupported format for label %s\", l)\n\t\t}\n\t\tval, err := strconv.Unquote(parts[1])\n\t\tif err != nil {\n\t\t\treturn labels.EmptyLabels(), errors.Wrap(err, \"unquote label value\")\n\t\t}\n\t\tlset.Add(parts[0], val)\n\t}\n\tlset.Sort()\n\treturn lset.Labels(), nil\n}\n\ntype goMemLimitConfig struct {\n\tenableAutoGoMemlimit bool\n\tmemlimitRatio        float64\n}\n\nfunc (gml *goMemLimitConfig) registerFlag(cmd extkingpin.FlagClause) *goMemLimitConfig {\n\tcmd.Flag(\"enable-auto-gomemlimit\",\n\t\t\"Enable go runtime to automatically limit memory consumption.\").\n\t\tDefault(\"false\").BoolVar(&gml.enableAutoGoMemlimit)\n\n\tcmd.Flag(\"auto-gomemlimit.ratio\",","sourceCodeStart":321,"sourceCodeEnd":357,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/cmd/thanos/config.go#L321-L357","documentation":"The label value (text after the first '=') must be a valid Go quoted string; parseFlagLabels runs strconv.Unquote on it. If Unquote fails (missing surrounding quotes with escapes, or unterminated quotes), the error is wrapped as \"unquote label value\" and returned. This lets values contain UTF-8 escapes and quoted characters.","triggerScenarios":"Passing --label key=\"value\" where the shell strips the quotes so Unquote sees a bare string containing an escape sequence (e.g. key=a\\nb), or a value with an unbalanced quote like key=\"value.","commonSituations":"Double-quoting confusion in shells (quotes consumed before Thanos sees them); documenting --label cluster=\"eu-1\" literally; Windows cmd quoting differences; copy-pasted examples where quotes were part of shell syntax.","solutions":["Quote the whole argument so quotes reach Thanos: --label 'key=\"value\"' (single-quote outside, double-quote inside).","If the value needs no escapes, pass it unquoted: --label key=value.","Ensure escape sequences are balanced and inside quotes, e.g. --label 'key=\"a\\nb\"'."],"exampleFix":"// before (shell strips quotes; \\n then fails Unquote)\nthanos sidecar --label note=a\\nb\n// after\nthanos sidecar --label 'note=\"a\\nb\"'","handlingStrategy":"validation","validationCode":"func unquotableLabelValue(l string) bool {\n    parts := strings.SplitN(l, \"=\", 2)\n    if len(parts) != 2 { return false }\n    _, err := strconv.Unquote(parts[1])\n    return err == nil\n}","typeGuard":null,"tryCatchPattern":"// Go\nif _, err := parseFlagLabels(args); err != nil {\n    var unwrap interface{ Unwrap() error }\n    _ = unwrap // errors.Wrap adds \"unquote label value\" context; log full chain\n}","preventionTips":["Use single quotes in shells so inner double quotes survive: --label 'k=\"v\"'.","Only quote values that actually need escapes; plain values need no quotes.","Test the exact command line in the same shell/runtime used in production (systemd, k8s)."],"tags":["cli","config","labels","quoting"],"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"}