{"record":{"id":"eb64875b81083305","repo":"larksuite/cli","slug":"s-alias-s-for-s-conflicts-with-existing-ali","errorCode":null,"errorMessage":"%s alias --%s for --%s conflicts with existing alias for --%s after normalization to --%s","messagePattern":"(.+?) alias --(.+?) for --(.+?) conflicts with existing alias for --(.+?) after normalization to --(.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/flagalias/flagalias.go","lineNumber":106,"sourceCode":"\t\t}\n\t\tseenCanonical[canonical] = struct{}{}\n\t\tcanonicalFlags[canonical] = canonicalFlag\n\t\tfor _, alias := range spec.Aliases {\n\t\t\tif err := validateAliasName(alias); err != nil {\n\t\t\t\treturn fmt.Errorf(\"%s alias for --%s: %w\", cmd.CommandPath(), canonical, err)\n\t\t\t}\n\t\t\tnormalized := normalize(alias)\n\t\t\tif normalized == \"\" {\n\t\t\t\treturn fmt.Errorf(\"%s alias --%s for --%s normalizes to an empty name\", cmd.CommandPath(), alias, canonical)\n\t\t\t}\n\t\t\tif normalized == canonical {\n\t\t\t\treturn fmt.Errorf(\"%s declares --%s as an alias of itself (--%s after normalization)\", cmd.CommandPath(), alias, canonical)\n\t\t\t}\n\t\t\tif existing, ok := registered[normalized]; ok {\n\t\t\t\treturn fmt.Errorf(\"%s alias --%s for --%s conflicts with registered flag --%s after normalization\", cmd.CommandPath(), alias, canonical, existing)\n\t\t\t}\n\t\t\tif existing, ok := acceptedAliases[normalized]; ok {\n\t\t\t\treturn fmt.Errorf(\"%s alias --%s for --%s conflicts with existing alias for --%s after normalization to --%s\", cmd.CommandPath(), alias, canonical, existing, normalized)\n\t\t\t}\n\t\t\tif existing, ok := aliases[normalized]; ok {\n\t\t\t\tif existing == canonical {\n\t\t\t\t\treturn fmt.Errorf(\"%s declares duplicate alias --%s for --%s after normalization to --%s\", cmd.CommandPath(), alias, canonical, normalized)\n\t\t\t\t}\n\t\t\t\treturn fmt.Errorf(\"%s alias --%s maps to both --%s and --%s after normalization to --%s\", cmd.CommandPath(), alias, existing, canonical, normalized)\n\t\t\t}\n\t\t\taliases[normalized] = canonical\n\t\t\tmetadata[canonicalFlag] = append(metadata[canonicalFlag], alias)\n\t\t}\n\t}\n\n\tif len(aliases) == 0 {\n\t\treturn nil\n\t}\n\ttracked := make(map[string]*trackedValue, len(canonicalFlags))\n\tfor canonical, flag := range canonicalFlags {\n\t\ttracked[canonical] = ensureTrackedValue(flag)","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/internal/flagalias/flagalias.go#L88-L124","documentation":"Bind rejects a declaration when the normalized alias name has already been accepted as an alias for a different canonical flag. Each normalized alias may map to exactly one canonical flag; a second mapping would make flag resolution nondeterministic. The error reports both the previously bound canonical flag and the normalized name so the conflicting declaration can be located.","triggerScenarios":"Two Bind alias entries normalize to the same string but target different canonical flags, e.g. Alias(\"logLevel\",\"LogLevel\") and Alias(\"log_level\",\"LogFields\") under a normalizer that strips underscores, so acceptedAliases[normalized] already holds the first canonical.","commonSituations":"Bulk alias tables generated from config where several entries collapse to the same normalized name; adding a new alias without checking existing ones; normalizer changes (new version) that newly merge previously distinct names.","solutions":["Rename one of the aliases so normalized names stay distinct","Map both aliases to the same canonical flag if that was the intent, removing the duplicate declaration","Tighten the normalizer (or disable it) so the two names do not collide","Audit the alias list before Bind with the same normalization to detect collisions early"],"exampleFix":"// before\nBind(cmd, Alias(\"logLevel\", \"LogLevel\"), Alias(\"log_level\", \"LogFields\"))\n// after\nBind(cmd, Alias(\"logLevel\", \"LogLevel\"), Alias(\"logFields\", \"LogFields\"))","handlingStrategy":"validation","validationCode":"func ensureUniqueAliases(aliases []flagalias.Alias, norm func(string) string) error {\n\tseen := map[string]string{}\n\tfor _, a := range aliases {\n\t\tn := norm(a.Alias)\n\t\tif owner, ok := seen[n]; ok && owner != a.Canonical {\n\t\t\treturn fmt.Errorf(\"alias %q maps to both %s and %s\", n, owner, a.Canonical)\n\t\t}\n\t\tseen[n] = a.Canonical\n\t}\n\treturn nil\n}","typeGuard":null,"tryCatchPattern":"if err := flagalias.MustBind(cmd, aliases...); err != nil {\n\tif strings.Contains(err.Error(), \"conflicts with existing alias\") {\n\t\treturn fmt.Errorf(\"alias table ambiguous, dedupe entries: %w\", err)\n\t}\n\treturn err\n}","preventionTips":["Deduplicate aliases by normalized name before Bind","Re-run alias collision checks whenever the normalizer changes","Generate alias tables from a single source of truth"],"tags":["go","cli","flag-alias","duplicate-registration"],"backgroundTag":"flag-alias-conflict","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"}