{"record":{"id":"8be74415a9b74ccd","repo":"larksuite/cli","slug":"name-q-must-not-contain-whitespace","errorCode":null,"errorMessage":"name %q must not contain whitespace","messagePattern":"name %q must not contain whitespace","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/flagalias/flagalias.go","lineNumber":278,"sourceCode":"\t\treturn value.trackedValue\n\t}\n\ttracked := &trackedValue{Value: flag.Value, canonical: flag.Name}\n\tif slice, ok := flag.Value.(pflag.SliceValue); ok {\n\t\tflag.Value = &trackedSliceValue{trackedValue: tracked, slice: slice}\n\t} else {\n\t\tflag.Value = tracked\n\t}\n\treturn tracked\n}\n\nfunc validateAliasName(name string) error {\n\tswitch {\n\tcase name == \"\":\n\t\treturn fmt.Errorf(\"name must not be empty\")\n\tcase strings.HasPrefix(name, \"-\"):\n\t\treturn fmt.Errorf(\"name %q must not include leading dashes\", name)\n\tcase strings.ContainsAny(name, \" \\t\\r\\n\"):\n\t\treturn fmt.Errorf(\"name %q must not contain whitespace\", name)\n\tcase strings.Contains(name, \"=\"):\n\t\treturn fmt.Errorf(\"name %q must not contain '='\", name)\n\tdefault:\n\t\treturn nil\n\t}\n}\n\nfunc collectRegistered(dst map[string]string, set *pflag.FlagSet) {\n\tif set == nil {\n\t\treturn\n\t}\n\tset.VisitAll(func(flag *pflag.Flag) {\n\t\tdst[flag.Name] = flag.Name\n\t})\n}\n\nfunc collectAnnotatedAliases(dst map[string]string, set *pflag.FlagSet, normalize func(string) string) {\n\tif set == nil {","sourceCodeStart":260,"sourceCodeEnd":296,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/internal/flagalias/flagalias.go#L260-L296","documentation":"validateAliasName enforces that alias names contain no whitespace characters (space, tab, CR, LF). Flag tokens on a command line can never contain whitespace without quoting, so a whitespace-containing alias would be unreachable and likely indicates a parsing or construction bug upstream. Bind rejects such specs at registration time rather than letting a dead alias silently ship.","triggerScenarios":"Calling flagalias.Bind with a Spec whose name contains a space, tab, or newline — e.g. Name: \"json output\", a name joined from a list with strings.Join(parts, \" \"), or a name read from a config file/line that still carries a trailing \"\\r\" (Windows CRLF) or \"\\n\".","commonSituations":"Names parsed from CSV or env files without TrimSpace; a CRLF left over from a Windows-edited config; templated flag names where a placeholder expanded to multiple words.","solutions":["Run strings.TrimSpace (and strip internal whitespace) on the name before constructing the Spec.","If the name should be two flags, split it into separate Specs instead of one whitespace-containing name.","Replace internal spaces with a valid separator such as '-' (e.g. \"json-output\").","If reading names from files, open with normalization for CRLF (strings.TrimRight(line, \"\\r\\n\")) before use."],"exampleFix":"// before\nname := line // e.g. \"json output\\r\"\nspecs = append(specs, flagalias.Spec{Name: name, Target: target})\n// after\nname := strings.TrimSpace(strings.ReplaceAll(line, \" \", \"-\"))\nspecs = append(specs, flagalias.Spec{Name: name, Target: target})","handlingStrategy":"validation","validationCode":"func normalizeSpecName(raw string) string {\n\treturn strings.TrimSpace(strings.Join(strings.Fields(raw), \"-\"))\n}\n// before Bind:\nif strings.ContainsAny(name, \" \\t\\r\\n\") {\n\treturn fmt.Errorf(\"alias name %q contains whitespace\", name)\n}","typeGuard":"func hasNoWhitespace(s string) bool {\n\treturn !strings.ContainsAny(s, \" \\t\\r\\n\")\n}","tryCatchPattern":null,"preventionTips":["TrimSpace every name read from files, env vars, or CLI input before use.","Normalize CRLF (\\r\\n) when parsing line-based config files.","Prefer '-' as the internal word separator for multi-word flag names."],"tags":["go","cli","flags","input-validation"],"backgroundTag":"invalid-flag-name","analyzedSha":"7fd6ef3c07182257ce776cdc5a614e122d5bd4b3","analyzedAt":"2026-09-04T21:17:44.649Z","contentChangedAt":"2026-09-04T21:17:44.649Z","schemaVersion":2},"datasetVersion":"2026-09-12T02:17:10.037Z"}