{"record":{"id":"e8ae4d30e72a5fbe","repo":"larksuite/cli","slug":"external-command-path-q-is-already-registered","errorCode":null,"errorMessage":"external command path %q is already registered","messagePattern":"external command path %q is already registered","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shortcuts/register.go","lineNumber":118,"sourceCode":"// costs ~165us over 500+ shortcuts, which lands on every CLI startup.\n//\n//go:noinline\nfunc AllShortcuts() []common.Shortcut {\n\treturn common.CloneHostedShortcuts(allShortcuts, commandbridge.Access{})\n}\n\n// AllShortcutsWithExternal returns one isolated shortcut snapshot after validating external path collisions.\nfunc AllShortcutsWithExternal(commands []common.Shortcut) ([]common.Shortcut, error) {\n\tregistered := AllShortcuts()\n\texternal := common.CloneHostedShortcuts(commands, commandbridge.Access{})\n\tpaths := make(map[string]struct{}, len(registered)+len(external))\n\tfor _, shortcut := range registered {\n\t\tpaths[shortcut.Service+\" \"+shortcut.Command] = struct{}{}\n\t}\n\tfor _, shortcut := range external {\n\t\tpath := shortcut.Service + \" \" + shortcut.Command\n\t\tif _, duplicate := paths[path]; duplicate {\n\t\t\treturn nil, fmt.Errorf(\"external command path %q is already registered\", path) //nolint:forbidigo // Intermediate build diagnostic wrapped by the command-set startup guard.\n\t\t}\n\t\tpaths[path] = struct{}{}\n\t}\n\treturn append(registered, external...), nil\n}\n\n// RegisterShortcuts registers all +shortcut commands on the program.\nfunc RegisterShortcuts(program *cobra.Command, f *cmdutil.Factory) {\n\tRegisterShortcutsWithContext(context.Background(), program, f)\n}\n\nfunc RegisterShortcutsWithContext(ctx context.Context, program *cobra.Command, f *cmdutil.Factory) {\n\tRegisterShortcutSnapshotWithContext(ctx, program, f, AllShortcuts())\n}\n\n// RegisterShortcutSnapshotWithContext mounts one build-local shortcut snapshot.\nfunc RegisterShortcutSnapshotWithContext(ctx context.Context, program *cobra.Command, f *cmdutil.Factory, registered []common.Shortcut) {\n\t// Factory.Config may be nil in tests that pass a zero-value factory.","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/shortcuts/register.go#L100-L136","documentation":"AllShortcutsWithExternal merges externally contributed shortcuts into the registered shortcut set and rejects duplicates on the `Service + \" \" + Command` path. This is a build/startup diagnostic: two plugins or contributions tried to register the same command path, which would make dispatch ambiguous.","triggerScenarios":"An external shortcut contribution declares a Service+Command pair identical to an existing built-in shortcut or to another external contribution — e.g. a plugin registering `mail send` when the core CLI already registers `mail send`.","commonSituations":"Installing two plugins that both register the same command path; a custom external contribution shadowing a built-in; copy-pasting a shortcut definition without changing Service or Command.","solutions":["Change the external contribution's Service or Command so its `Service + \" \" + Command` path is unique.","Remove the duplicate plugin/contribution that is colliding with the built-in command.","Run the failing tests or startup guard output to identify both contributions claiming the path, then keep one."],"exampleFix":"// before\ncommon.Shortcut{Service: \"mail\", Command: \"send\", ...} // collides with built-in\n// after\ncommon.Shortcut{Service: \"mail\", Command: \"send-draft\", ...}","handlingStrategy":"validation","validationCode":"seen := map[string]bool{}\nfor _, s := range append(builtin, external...) {\n    p := s.Service + \" \" + s.Command\n    if seen[p] {\n        return fmt.Errorf(\"duplicate path %q\", p)\n    }\n    seen[p] = true\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Namespace plugin contributions with a unique Service prefix.","Check the built-in shortcut catalog before picking Service/Command names.","Run the shortcut-registration tests after adding any external contribution."],"tags":["cli","shortcut-registration","duplicate"],"backgroundTag":"duplicate-command-registration","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"}