{"record":{"id":"dcb3854d3d1fe241","repo":"larksuite/cli","slug":"argstype-and-datatype-are-required","errorCode":null,"errorMessage":"ArgsType and DataType are required","messagePattern":"ArgsType and DataType are required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shortcuts/common/typed_external.go","lineNumber":22,"sourceCode":"//nolint:forbidigo // Definition diagnostics are build-time errors wrapped by the command-set startup guard.\npackage common\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\t\"io\"\n\t\"reflect\"\n\n\t\"github.com/larksuite/cli/internal/commandbridge\"\n)\n\n// CompileCommandDefinition is the single sealed entry from commandhost into\n// the existing shortcut compiler. All authoring fields retain\n// extension/command as their owner; the internal token prevents this function\n// from becoming a second public compiler API.\nfunc CompileCommandDefinition(definition commandbridge.Definition, _ commandbridge.Access) (Shortcut, error) {\n\tif definition.ArgsType == nil || definition.DataType == nil {\n\t\treturn Shortcut{}, fmt.Errorf(\"ArgsType and DataType are required\")\n\t}\n\tif definition.Hooks.NewArgs == nil {\n\t\treturn Shortcut{}, fmt.Errorf(\"Hooks.NewArgs is required\")\n\t}\n\tnewArgs, err := probeNewArgs(definition.Hooks.NewArgs)\n\tif err != nil {\n\t\treturn Shortcut{}, err\n\t}\n\tif newArgs == nil || reflect.TypeOf(newArgs) != reflect.PointerTo(definition.ArgsType) {\n\t\treturn Shortcut{}, fmt.Errorf(\"Hooks.NewArgs must return *%s\", definition.ArgsType)\n\t}\n\n\toutput := definition.Output\n\tif definition.PageOutput {\n\t\toutput.Meta.Pagination = true\n\t}\n\tcompiled, err := compileDefinitionParts(\n\t\tdefinition.Metadata,","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/shortcuts/common/typed_external.go#L4-L40","documentation":"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.","triggerScenarios":"Constructing commandbridge.Definition without setting ArgsType or DataType (nil reflect.Type); wiring a command through compileCommand with a partially filled definition struct.","commonSituations":"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.","solutions":["Set definition.ArgsType = reflect.TypeOf(MyArgs{}) and definition.DataType = reflect.TypeOf(MyData{})","Ensure the struct passed to CompileCommandDefinition is fully populated, not zero-valued","Check the command registration path (compileCommand) for fields dropped during construction"],"exampleFix":"// before\nreturn common.CompileCommandDefinition(commandbridge.Definition{\n    Metadata: meta, Hooks: hooks,\n}, access)\n// after\nreturn common.CompileCommandDefinition(commandbridge.Definition{\n    Metadata: meta, Hooks: hooks,\n    ArgsType: reflect.TypeOf(argsType{}),\n    DataType: reflect.TypeOf(dataType{}),\n}, access)","handlingStrategy":"type-guard","validationCode":"if definition.ArgsType == nil || definition.DataType == nil { return errors.New(\"ArgsType and DataType are required\") }","typeGuard":"func hasTypedContract(d commandbridge.Definition) bool { return d.ArgsType != nil && d.DataType != nil }","tryCatchPattern":"sc, err := common.CompileCommandDefinition(def, access)\nif err != nil {\n    return fmt.Errorf(\"compile %s: %w\", def.Metadata.Command, err)\n}","preventionTips":["Always set ArgsType and DataType via reflect.TypeOf immediately after defining args/data structs","Use a constructor helper that requires both types as parameters","Run compile/startup early in CI so missing fields surface at build time"],"tags":["go","shortcut-compiler","commandbridge","missing-field"],"backgroundTag":"missing-required-argument","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"}