larksuite/cli · error
name must not be empty
Error message
name must not be empty
What it means
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.
Source
Thrown at internal/flagalias/flagalias.go:274
if value, ok := flag.Value.(*trackedValue); ok {
return value
}
if value, ok := flag.Value.(*trackedSliceValue); ok {
return value.trackedValue
}
tracked := &trackedValue{Value: flag.Value, canonical: flag.Name}
if slice, ok := flag.Value.(pflag.SliceValue); ok {
flag.Value = &trackedSliceValue{trackedValue: tracked, slice: slice}
} else {
flag.Value = tracked
}
return tracked
}
func validateAliasName(name string) error {
switch {
case name == "":
return fmt.Errorf("name must not be empty")
case strings.HasPrefix(name, "-"):
return fmt.Errorf("name %q must not include leading dashes", name)
case strings.ContainsAny(name, " \t\r\n"):
return fmt.Errorf("name %q must not contain whitespace", name)
case strings.Contains(name, "="):
return fmt.Errorf("name %q must not contain '='", name)
default:
return nil
}
}
func collectRegistered(dst map[string]string, set *pflag.FlagSet) {
if set == nil {
return
}
set.VisitAll(func(flag *pflag.Flag) {
dst[flag.Name] = flag.Name
})View on GitHub (pinned to 7fd6ef3c07)
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
Example fix
// before
alias := os.Getenv("FLAG_ALIAS") // may be ""
Bind(cmd, Alias(alias, "Verbose"))
// after
alias := os.Getenv("FLAG_ALIAS")
if alias == "" { return errors.New("FLAG_ALIAS must be set") }
Bind(cmd, Alias(alias, "Verbose")) Defensive patterns
Strategy: validation
Validate before calling
func validName(s string) bool {
s = strings.TrimSpace(s)
return s != "" && !strings.HasPrefix(s, "-") && !strings.ContainsAny(s, " \t\r\n=")
}
// call before Bind: if !validName(alias) || !validName(canonical) { fail } Type guard
func nonEmpty(s string) (string, bool) {
s = strings.TrimSpace(s)
return s, s != ""
} Try / catch
if err := flagalias.MustBind(cmd, aliases...); err != nil {
if strings.Contains(err.Error(), "must not be empty") || strings.Contains(err.Error(), "must not include") {
return fmt.Errorf("invalid alias name in config: %w", err)
}
return err
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- %s alias --%s for --%s conflicts with registered flag --%s a
- %s alias --%s for --%s conflicts with existing alias for --%
- %s declares duplicate alias --%s for --%s after normalizatio
- %s alias --%s maps to both --%s and --%s after normalization
- name %q must not include leading dashes
AI-assisted analysis of larksuite/cli@7fd6ef3c07 (2026-09-04).
Data as JSON: /api/errors/2ab6452e05dad128.
Report an issue: GitHub.