{"record":{"id":"c04fb009609b6ed9","repo":"larksuite/cli","slug":"s-declares-duplicate-alias-s-for-s-after-no","errorCode":null,"errorMessage":"%s declares duplicate alias --%s for --%s after normalization to --%s","messagePattern":"(.+?) declares duplicate alias --(.+?) for --(.+?) after normalization to --(.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/flagalias/flagalias.go","lineNumber":110,"sourceCode":"\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)\n\t}\n\tfor flag, names := range metadata {\n\t\tsetAliases(flag, append(Aliases(flag), names...))\n\t}","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/internal/flagalias/flagalias.go#L92-L128","documentation":"Bind rejects declaring the exact same alias twice for the same canonical flag once names are normalized. The mapping is already recorded in aliases[normalized] = canonical, so a repeated declaration is redundant and treated as a configuration mistake rather than silently ignored. The error names the command, the duplicated alias, the canonical flag, and the normalized form.","triggerScenarios":"An alias list passed to Bind (or accumulated across calls to Bind on the same command) contains the same alias string twice for one canonical flag, e.g. Alias(\"verbose\",\"Verbose\") appearing twice, or \"Verbose\" and \"verbose\" under a lowercasing normalizer.","commonSituations":"Merging alias configs from multiple sources without deduplication; copy-paste in a large alias table; version changes that add an alias already present.","solutions":["Remove the duplicate alias entry from the list passed to Bind","Deduplicate the alias configuration before binding (e.g. with a map keyed by normalized name)","If the duplicate comes from merging configs, make the merge idempotent"],"exampleFix":"// before\nBind(cmd, Alias(\"verbose\", \"Verbose\"), Alias(\"verbose\", \"Verbose\"))\n// after\nBind(cmd, Alias(\"verbose\", \"Verbose\"))","handlingStrategy":"validation","validationCode":"func dedupeAliases(aliases []flagalias.Alias, norm func(string) string) []flagalias.Alias {\n\tseen := map[string]bool{}\n\tout := aliases[:0]\n\tfor _, a := range aliases {\n\t\tk := norm(a.Alias) + \"->\" + a.Canonical\n\t\tif !seen[k] { seen[k] = true; out = append(out, a) }\n\t}\n\treturn out\n}","typeGuard":null,"tryCatchPattern":"if err := flagalias.MustBind(cmd, aliases...); err != nil {\n\tif strings.Contains(err.Error(), \"declares duplicate alias\") {\n\t\treturn fmt.Errorf(\"remove duplicate alias entries: %w\", err)\n\t}\n\treturn err\n}","preventionTips":["Deduplicate the alias slice before passing it to Bind","Treat alias tables as sets, not lists, when merging configs","Add a lint/test that normalizes and dedupes alias definitions"],"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"}