gastownhall/beads · warning

label %q is empty after trimming whitespace

Error message

label %q is empty after trimming whitespace

What it means

`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.

Source

Thrown at cmd/bd/tag.go:115

// normalizeLabelForTag applies to `bd tag` the normalization every other CLI
// label write performs, and it is deliberately called BEFORE the route split so
// the direct and proxied paths cannot diverge on it.
//
// `bd tag` describes itself as "Shorthand for 'bd update <id> --add-label
// <label>'". Without this it was not: update trims and warns, tag stored the
// positional verbatim, so `bd tag bd-1 ' theme:a'` wrote a label that no
// `--label theme:a` filter can ever match — the exact unfilterable class #5812
// is about, written by the command whose help text promises equivalence.
//
// A label that is only whitespace is rejected rather than silently dropped.
// The plural flags can drop an empty element and still honor the rest of the
// request; `bd tag` has exactly one label to add, so dropping it would leave a
// command that reported success having done nothing.
func normalizeLabelForTag(raw string) (string, error) {
	labels := utils.NormalizeLabels([]string{raw})
	if len(labels) == 0 {
		return "", fmt.Errorf("label %q is empty after trimming whitespace", raw)
	}
	warnLabelsContainingWhitespace(labels)
	return labels[0], nil
}

func init() {
	tagCmd.ValidArgsFunction = issueIDCompletion
	rootCmd.AddCommand(tagCmd)
}

View on GitHub (pinned to 71377f2769)

Solutions

  1. Provide a non-empty label: bd tag bd-42 add bug
  2. Trim/guard label variables in scripts before invoking bd tag
  3. For multiple labels, pass them via the plural flags (e.g. --label) which tolerate empty elements

Example fix

// before
bd tag "$ID" add "$LABEL"   # LABEL may be empty
// after
[ -n "${LABEL//[[:space:]]/}" ] || { echo "LABEL is empty"; exit 1; }
bd tag "$ID" add "$LABEL"
Defensive patterns

Strategy: validation

Validate before calling

trimmed=$(printf '%s' "$LABEL" | tr -d '[:space:]')
if [ -z "$trimmed" ]; then echo "label must be non-empty" >&2; exit 2; fi
bd tag "$ID" add "$LABEL"

Try / catch

if _, err := normalizeLabelForTag(raw); err != nil {
    return fmt.Errorf("usage: bd tag <id> add <non-empty-label>: %w", err)
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of gastownhall/beads@71377f2769 (2026-08-30). Data as JSON: /api/errors/6d1e54861327fd8b. Report an issue: GitHub.