{"record":{"id":"148739a2e34d1b1c","repo":"larksuite/cli","slug":"hooks-newargs-is-required","errorCode":null,"errorMessage":"Hooks.NewArgs is required","messagePattern":"Hooks\\.NewArgs is required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shortcuts/common/typed_external.go","lineNumber":25,"sourceCode":"import (\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,\n\t\tdefinition.Input,\n\t\toutput,\n\t\tdefinition.ArgsType,","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/shortcuts/common/typed_external.go#L7-L43","documentation":"Besides the type pair, CompileCommandDefinition requires Hooks.NewArgs — the hook that constructs a fresh args pointer for each invocation. A nil NewArgs hook means the runtime could never instantiate the command's args, so compilation is rejected.","triggerScenarios":"definition.Hooks.NewArgs left nil while ArgsType/DataType are set; building Hooks struct literal without the NewArgs field; a hook removed during refactoring.","commonSituations":"Authoring a new typed command and populating only Hooks.Execute; copying a Hooks literal from a command that used a different construction pattern; zero-value Hooks struct.","solutions":["Set Hooks.NewArgs to a function returning a pointer to the args type: func() any { return &MyArgs{} }","Ensure the Hooks struct literal includes NewArgs alongside Execute/Renderers","If args are genuinely absent, that is unsupported — every typed command needs an args type and NewArgs"],"exampleFix":"// before\nHooks: commandbridge.Hooks{Execute: execute},\n// after\nHooks: commandbridge.Hooks{Execute: execute, NewArgs: func() any { return &MyArgs{} }},","handlingStrategy":"type-guard","validationCode":"if definition.Hooks.NewArgs == nil { return errors.New(\"Hooks.NewArgs is required\") }","typeGuard":"func hasNewArgs(h commandbridge.Hooks) bool { return h.NewArgs != nil }","tryCatchPattern":"sc, err := common.CompileCommandDefinition(def, access)\nif err != nil {\n    return fmt.Errorf(\"compile %s: %w\", def.Metadata.Command, err)\n}","preventionTips":["Provide NewArgs together with Execute in every Hooks literal","Use a shared helper that builds Hooks with NewArgs mandatory","Compile all commands in a startup test so missing hooks fail fast"],"tags":["go","shortcut-compiler","commandbridge","missing-field","hooks"],"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"}