larksuite/cli · error

command set %d command %d (%s): %w

Error message

command set %d command %d (%s): %w

What it means

This wraps any error returned by compileCommand for an individual shortcut definition, adding its position and path for diagnosis. CompileSets fails atomically: one bad definition prevents the whole set from compiling.

Source

Thrown at internal/commandhost/compile.go:60

			return nil, fmt.Errorf("command set %d: %w", setIndex+1, err)
		}
		if len(set.Commands) == 0 {
			return nil, fmt.Errorf("command set %d for domain %q has no commands", setIndex+1, domain.Name)
		}
		for commandIndex, declaration := range set.Commands {
			definition := command.InspectCommand(declaration)
			if string(definition.Metadata.Service) != domain.Name {
				return nil, fmt.Errorf("command set %d command %d: Metadata.Service %q does not match domain %q",
					setIndex+1, commandIndex+1, definition.Metadata.Service, domain.Name)
			}
			shortcutPath := string(definition.Metadata.Service) + " " + definition.Metadata.Command
			if owner, duplicate := paths[shortcutPath]; duplicate {
				return nil, fmt.Errorf("command set %d command %d: command path %q conflicts with %s",
					setIndex+1, commandIndex+1, shortcutPath, owner)
			}
			shortcut, err := compileCommand(definition)
			if err != nil {
				return nil, fmt.Errorf("command set %d command %d (%s): %w", setIndex+1, commandIndex+1, shortcutPath, err)
			}
			paths[shortcutPath] = fmt.Sprintf("command set %d command %d", setIndex+1, commandIndex+1)
			compiled = append(compiled, shortcut)
		}
	}
	return compiled, nil
}

// ValidateDeclaration compiles one declaration through the production compiler
// and discards the result. A business test harness calls it so a wrong tag,
// Shape or relation fails in the unit test rather than at CLI startup: executing
// hooks directly exercises none of the compiler's contract checks, which is the
// gap that let a green test ship a command that cannot mount.
//
// Domain existence and path collisions are deliberately not checked here. Those
// are properties of a whole contribution and belong to CompileSets, which runs
// during build.
func ValidateDeclaration(declaration command.Command) error {

View on GitHub (pinned to 7fd6ef3c07)

Solutions

  1. Read the wrapped cause (%w) after this prefix — it names the actual failing invariant
  2. Fix the offending HostDefinition at 'command set N command M' indicated in the message
  3. If the cause is a dry-run request error, fix the view per ValidateRequestView
Defensive patterns

Strategy: try-catch

Validate before calling

// Pre-validate definitions: non-empty Service/Command, hooks and dry-run views populated per command.HostDefinition contract.

Try / catch

compiled, err := commandhost.CompileSets(sets)
var pathErr *fmt.WrapError // or unwrap chain
if err != nil {
    return fmt.Errorf("compiling business command sets: %w", err) // preserves the 'command set N command M' context
}

Prevention

When it happens

Trigger: A HostDefinition fails internal validation in compileCommand — e.g. invalid hooks, malformed dry-run view, or another definition-level invariant — during CompileSets.

Common situations: A newly added shortcut with an incorrectly wired hook or dry-run request view; a refactor changed compileCommand's contract and existing definitions no longer validate.

Related errors


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