larksuite/cli · critical
Hooks.Execute is required
Error message
Hooks.Execute is required
What it means
The typed command bridge requires an Execute hook: the function that performs the command's actual work and returns its data. compileDefinitionParts rejects any definition whose compiledHooks.execute is nil, because a command without an executor can never produce output. This is a build/startup-time declaration error, not a runtime failure.
Source
Thrown at shortcuts/common/typed_compiler.go:44
return nil, err
}
fields, fieldByName, err := compileInput(argsType, input)
if err != nil {
return nil, err
}
relations, err := compileRelations(input.Relations, fieldByName)
if err != nil {
return nil, err
}
if err := compileAuthorization(metadata.Authorization, fields, fieldByName); err != nil {
return nil, err
}
dataShape, err := compileData(dataType, output.Data)
if err != nil {
return nil, err
}
if hooks.execute == nil {
return nil, fmt.Errorf("Hooks.Execute is required")
}
if err := validateOutput(output, dataShape); err != nil {
return nil, err
}
if err := validateOutputHooks(output, renderers); err != nil {
return nil, err
}
command := &compiledCommand{
metadata: metadata,
argsType: argsType,
dataType: dataType,
fields: fields,
fieldByName: fieldByName,
relations: relations,
dataShape: dataShape,
output: output,
hooks: hooks,
pageOutput: pageOutput,View on GitHub (pinned to 7fd6ef3c07)
Solutions
- Implement and assign Hooks.Execute before compiling the definition.
- If the command is not ready, remove its definition entirely rather than registering it without an executor.
- Verify the hooks struct/value passed to the bridge is fully initialized (not a typed-nil function).
Example fix
// before
var cmd = common.Define(..., common.Hooks{})
// after
var cmd = common.Define(..., common.Hooks{
Execute: func(ctx context.Context, rt *common.RuntimeContext, args Args) (Data, error) { ... },
}) Defensive patterns
Strategy: validation
Validate before calling
if hooks.Execute == nil {
return fmt.Errorf("command %s: Hooks.Execute must be assigned before definition", name)
} Type guard
func executeReady(h common.Hooks) bool { return h.Execute != nil } Prevention
- Always define Execute together with the command definition in the same commit.
- Avoid nil function variables for hooks; write the function literal inline.
- If a command is unfinished, keep it unregistered until Execute exists.
When it happens
Trigger: CompileCommandDefinition (or defineTypedCommand) invoked with Hooks whose Execute field is nil — e.g. common.Hooks{} with no Execute assigned, or a nil function variable passed as Execute.
Common situations: Scaffolding a new command and forgetting to implement Execute; deliberately commenting out Execute during debugging; wiring hooks from a struct whose Execute field was never populated.
Related errors
- Hooks.Renderers[%q] is nil
- Hooks.Renderers[%q] is invalid: custom renderers are only su
- Hooks.Renderers[%q] conflicts with Output.Mode %q: fixed JSO
- Metadata.Service is required
- %v
AI-assisted analysis of larksuite/cli@7fd6ef3c07 (2026-09-04).
Data as JSON: /api/errors/deff783e14703869.
Report an issue: GitHub.