larksuite/cli · error

ArgsType and DataType are required

Error message

ArgsType and DataType are required

What it means

CompileCommandDefinition, the sealed entry from commandhost into the shortcut compiler, requires both ArgsType and DataType (reflect.Type values) on the bridge Definition. A nil either means the command has no typed input or output contract, which the compiler cannot compile.

Source

Thrown at shortcuts/common/typed_external.go:22

//nolint:forbidigo // Definition diagnostics are build-time errors wrapped by the command-set startup guard.
package common

import (
	"context"
	"fmt"
	"io"
	"reflect"

	"github.com/larksuite/cli/internal/commandbridge"
)

// CompileCommandDefinition is the single sealed entry from commandhost into
// the existing shortcut compiler. All authoring fields retain
// extension/command as their owner; the internal token prevents this function
// from becoming a second public compiler API.
func CompileCommandDefinition(definition commandbridge.Definition, _ commandbridge.Access) (Shortcut, error) {
	if definition.ArgsType == nil || definition.DataType == nil {
		return Shortcut{}, fmt.Errorf("ArgsType and DataType are required")
	}
	if definition.Hooks.NewArgs == nil {
		return Shortcut{}, fmt.Errorf("Hooks.NewArgs is required")
	}
	newArgs, err := probeNewArgs(definition.Hooks.NewArgs)
	if err != nil {
		return Shortcut{}, err
	}
	if newArgs == nil || reflect.TypeOf(newArgs) != reflect.PointerTo(definition.ArgsType) {
		return Shortcut{}, fmt.Errorf("Hooks.NewArgs must return *%s", definition.ArgsType)
	}

	output := definition.Output
	if definition.PageOutput {
		output.Meta.Pagination = true
	}
	compiled, err := compileDefinitionParts(
		definition.Metadata,

View on GitHub (pinned to 7fd6ef3c07)

Solutions

  1. Set definition.ArgsType = reflect.TypeOf(MyArgs{}) and definition.DataType = reflect.TypeOf(MyData{})
  2. Ensure the struct passed to CompileCommandDefinition is fully populated, not zero-valued
  3. Check the command registration path (compileCommand) for fields dropped during construction

Example fix

// before
return common.CompileCommandDefinition(commandbridge.Definition{
    Metadata: meta, Hooks: hooks,
}, access)
// after
return common.CompileCommandDefinition(commandbridge.Definition{
    Metadata: meta, Hooks: hooks,
    ArgsType: reflect.TypeOf(argsType{}),
    DataType: reflect.TypeOf(dataType{}),
}, access)
Defensive patterns

Strategy: type-guard

Validate before calling

if definition.ArgsType == nil || definition.DataType == nil { return errors.New("ArgsType and DataType are required") }

Type guard

func hasTypedContract(d commandbridge.Definition) bool { return d.ArgsType != nil && d.DataType != nil }

Try / catch

sc, err := common.CompileCommandDefinition(def, access)
if err != nil {
    return fmt.Errorf("compile %s: %w", def.Metadata.Command, err)
}

Prevention

When it happens

Trigger: Constructing commandbridge.Definition without setting ArgsType or DataType (nil reflect.Type); wiring a command through compileCommand with a partially filled definition struct.

Common situations: Registering a new command and forgetting to set the reflect.TypeOf(...) fields; a refactor that removed the args/data type assignments; zero-value Definition structs passed directly.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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