{"record":{"id":"2ab6452e05dad128","repo":"larksuite/cli","slug":"name-must-not-be-empty","errorCode":null,"errorMessage":"name must not be empty","messagePattern":"name must not be empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/flagalias/flagalias.go","lineNumber":274,"sourceCode":"\tif value, ok := flag.Value.(*trackedValue); ok {\n\t\treturn value\n\t}\n\tif value, ok := flag.Value.(*trackedSliceValue); ok {\n\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})","sourceCodeStart":256,"sourceCodeEnd":292,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/internal/flagalias/flagalias.go#L256-L292","documentation":"validateAliasName rejects an empty alias or flag name string. An empty name cannot be rendered as --<name>, would collide with every other empty string after normalization, and is always a caller bug rather than valid input. Bind invokes this validator for alias and canonical names before registration proceeds.","triggerScenarios":"Passing \"\" as the alias or canonical flag name to Bind/MustBind, typically from an unset string variable, a missing map/config entry, or strings.TrimSpace producing an empty value from whitespace-only input.","commonSituations":"Loading alias definitions from YAML/JSON where a key or value is missing or blank; environment variables that are unset and read as empty strings; refactoring that changed a constant to an empty default.","solutions":["Supply a non-empty name for the alias/canonical flag","Trim and check names before calling Bind, failing fast with a clear config error","Fix the source config/env so the name field is populated"],"exampleFix":"// before\nalias := os.Getenv(\"FLAG_ALIAS\") // may be \"\"\nBind(cmd, Alias(alias, \"Verbose\"))\n// after\nalias := os.Getenv(\"FLAG_ALIAS\")\nif alias == \"\" { return errors.New(\"FLAG_ALIAS must be set\") }\nBind(cmd, Alias(alias, \"Verbose\"))","handlingStrategy":"validation","validationCode":"func validName(s string) bool {\n\ts = strings.TrimSpace(s)\n\treturn s != \"\" && !strings.HasPrefix(s, \"-\") && !strings.ContainsAny(s, \" \\t\\r\\n=\")\n}\n// call before Bind: if !validName(alias) || !validName(canonical) { fail }","typeGuard":"func nonEmpty(s string) (string, bool) {\n\ts = strings.TrimSpace(s)\n\treturn s, s != \"\"\n}","tryCatchPattern":"if err := flagalias.MustBind(cmd, aliases...); err != nil {\n\tif strings.Contains(err.Error(), \"must not be empty\") || strings.Contains(err.Error(), \"must not include\") {\n\t\treturn fmt.Errorf(\"invalid alias name in config: %w\", err)\n\t}\n\treturn err\n}","preventionTips":["Validate names (non-empty, no dashes/whitespace/=) when loading alias config, before Bind","Fail fast on empty env/config values instead of passing them through","Trim whitespace from names read from config files or environment variables"],"tags":["go","cli","flag-alias","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"}