{"record":{"id":"6d1e54861327fd8b","repo":"gastownhall/beads","slug":"label-q-is-empty-after-trimming-whitespace","errorCode":null,"errorMessage":"label %q is empty after trimming whitespace","messagePattern":"label %q is empty after trimming whitespace","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"cmd/bd/tag.go","lineNumber":115,"sourceCode":"\n// normalizeLabelForTag applies to `bd tag` the normalization every other CLI\n// label write performs, and it is deliberately called BEFORE the route split so\n// the direct and proxied paths cannot diverge on it.\n//\n// `bd tag` describes itself as \"Shorthand for 'bd update <id> --add-label\n// <label>'\". Without this it was not: update trims and warns, tag stored the\n// positional verbatim, so `bd tag bd-1 ' theme:a'` wrote a label that no\n// `--label theme:a` filter can ever match — the exact unfilterable class #5812\n// is about, written by the command whose help text promises equivalence.\n//\n// A label that is only whitespace is rejected rather than silently dropped.\n// The plural flags can drop an empty element and still honor the rest of the\n// request; `bd tag` has exactly one label to add, so dropping it would leave a\n// command that reported success having done nothing.\nfunc normalizeLabelForTag(raw string) (string, error) {\n\tlabels := utils.NormalizeLabels([]string{raw})\n\tif len(labels) == 0 {\n\t\treturn \"\", fmt.Errorf(\"label %q is empty after trimming whitespace\", raw)\n\t}\n\twarnLabelsContainingWhitespace(labels)\n\treturn labels[0], nil\n}\n\nfunc init() {\n\ttagCmd.ValidArgsFunction = issueIDCompletion\n\trootCmd.AddCommand(tagCmd)\n}\n","sourceCodeStart":97,"sourceCodeEnd":125,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/tag.go#L97-L125","documentation":"`bd tag` requires exactly one label, and normalizeLabelForTag runs the raw argument through utils.NormalizeLabels (which trims whitespace and drops empties). If the label is empty or pure whitespace, normalization yields zero labels and this error is thrown. This is deliberate: unlike plural-flag paths that can drop empty elements, dropping the single tag argument would silently succeed while doing nothing.","triggerScenarios":"Calling `bd tag <id> add \"\"` or passing a whitespace-only label (e.g. `bd tag bd-1 add \"   \"`), or a shell variable containing only spaces expanding into the label position.","commonSituations":"Scripting with an unset/empty TAG variable; copy-pasting a command where the label got lost; an editor or CI template leaving a placeholder blank.","solutions":["Provide a non-empty label: bd tag bd-42 add bug","Trim/guard label variables in scripts before invoking bd tag","For multiple labels, pass them via the plural flags (e.g. --label) which tolerate empty elements"],"exampleFix":"// before\nbd tag \"$ID\" add \"$LABEL\"   # LABEL may be empty\n// after\n[ -n \"${LABEL//[[:space:]]/}\" ] || { echo \"LABEL is empty\"; exit 1; }\nbd tag \"$ID\" add \"$LABEL\"","handlingStrategy":"validation","validationCode":"trimmed=$(printf '%s' \"$LABEL\" | tr -d '[:space:]')\nif [ -z \"$trimmed\" ]; then echo \"label must be non-empty\" >&2; exit 2; fi\nbd tag \"$ID\" add \"$LABEL\"","typeGuard":null,"tryCatchPattern":"if _, err := normalizeLabelForTag(raw); err != nil {\n    return fmt.Errorf(\"usage: bd tag <id> add <non-empty-label>: %w\", err)\n}","preventionTips":["Never pass unset or whitespace-only shell variables as the label","Remember `bd tag` takes exactly one label and will not silently drop it","Prefer the plural --label flags when labels may be conditionally empty"],"tags":["labels","cli","input-validation"],"backgroundTag":"empty-label","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}