larksuite/cli · error

external command path %q is already registered

Error message

external command path %q is already registered

What it means

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.

Source

Thrown at shortcuts/register.go:118

// costs ~165us over 500+ shortcuts, which lands on every CLI startup.
//
//go:noinline
func AllShortcuts() []common.Shortcut {
	return common.CloneHostedShortcuts(allShortcuts, commandbridge.Access{})
}

// AllShortcutsWithExternal returns one isolated shortcut snapshot after validating external path collisions.
func AllShortcutsWithExternal(commands []common.Shortcut) ([]common.Shortcut, error) {
	registered := AllShortcuts()
	external := common.CloneHostedShortcuts(commands, commandbridge.Access{})
	paths := make(map[string]struct{}, len(registered)+len(external))
	for _, shortcut := range registered {
		paths[shortcut.Service+" "+shortcut.Command] = struct{}{}
	}
	for _, shortcut := range external {
		path := shortcut.Service + " " + shortcut.Command
		if _, duplicate := paths[path]; duplicate {
			return nil, fmt.Errorf("external command path %q is already registered", path) //nolint:forbidigo // Intermediate build diagnostic wrapped by the command-set startup guard.
		}
		paths[path] = struct{}{}
	}
	return append(registered, external...), nil
}

// RegisterShortcuts registers all +shortcut commands on the program.
func RegisterShortcuts(program *cobra.Command, f *cmdutil.Factory) {
	RegisterShortcutsWithContext(context.Background(), program, f)
}

func RegisterShortcutsWithContext(ctx context.Context, program *cobra.Command, f *cmdutil.Factory) {
	RegisterShortcutSnapshotWithContext(ctx, program, f, AllShortcuts())
}

// RegisterShortcutSnapshotWithContext mounts one build-local shortcut snapshot.
func RegisterShortcutSnapshotWithContext(ctx context.Context, program *cobra.Command, f *cmdutil.Factory, registered []common.Shortcut) {
	// Factory.Config may be nil in tests that pass a zero-value factory.

View on GitHub (pinned to 7fd6ef3c07)

Solutions

  1. Change the external contribution's Service or Command so its `Service + " " + Command` path is unique.
  2. Remove the duplicate plugin/contribution that is colliding with the built-in command.
  3. Run the failing tests or startup guard output to identify both contributions claiming the path, then keep one.

Example fix

// before
common.Shortcut{Service: "mail", Command: "send", ...} // collides with built-in
// after
common.Shortcut{Service: "mail", Command: "send-draft", ...}
Defensive patterns

Strategy: validation

Validate before calling

seen := map[string]bool{}
for _, s := range append(builtin, external...) {
    p := s.Service + " " + s.Command
    if seen[p] {
        return fmt.Errorf("duplicate path %q", p)
    }
    seen[p] = true
}

Prevention

When it happens

Trigger: 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`.

Common situations: 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.

Related errors


AI-assisted analysis of larksuite/cli@7fd6ef3c07 (2026-09-04). Data as JSON: /api/errors/e8ae4d30e72a5fbe. Report an issue: GitHub.