{"record":{"id":"312999b62f5cf7f9","repo":"larksuite/cli","slug":"args-must-be-a-non-pointer-struct-got-s","errorCode":null,"errorMessage":"Args must be a non-pointer struct, got %s","messagePattern":"Args must be a non-pointer struct, got (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shortcuts/common/typed_compile_args.go","lineNumber":26,"sourceCode":"\t\"encoding/json\"\n\t\"fmt\"\n\t\"math\"\n\t\"reflect\"\n\t\"regexp\"\n\t\"strconv\"\n\t\"strings\"\n)\n\nvar (\n\tflagNamePattern  = regexp.MustCompile(`^[a-z0-9]+(?:-[a-z0-9]+)*$`)\n\taliasNamePattern = regexp.MustCompile(`^[a-z0-9][a-z0-9_-]*$`)\n)\n\nconst extensionCommandPkgPath = \"github.com/larksuite/cli/extension/command\"\n\nfunc compileInput(argsType reflect.Type, definition typedInputDefinition) ([]compiledInputField, map[string]int, error) {\n\tif argsType.Kind() != reflect.Struct {\n\t\treturn nil, nil, fmt.Errorf(\"Args must be a non-pointer struct, got %s\", argsType)\n\t}\n\tsupplements := make(map[string]typedInputField, len(definition.Fields))\n\tfor i, supplement := range definition.Fields {\n\t\tif !flagNamePattern.MatchString(supplement.Name) {\n\t\t\treturn nil, nil, fmt.Errorf(\"Input.Fields[%d].Name %q is not a canonical flag name\", i, supplement.Name)\n\t\t}\n\t\tif _, exists := supplements[supplement.Name]; exists {\n\t\t\treturn nil, nil, fmt.Errorf(\"Input.Fields contains duplicate flag %q\", supplement.Name)\n\t\t}\n\t\tsupplements[supplement.Name] = supplement\n\t}\n\tvar fields []compiledInputField\n\tseenGo := make(map[string]struct{})\n\tif err := collectArgFields(argsType, nil, false, &fields, seenGo, supplements); err != nil {\n\t\treturn nil, nil, err\n\t}\n\tfieldByName := make(map[string]int, len(fields))\n\tallNames := make(map[string]string, len(fields))","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/shortcuts/common/typed_compile_args.go#L8-L44","documentation":"compileInput validates the Args struct type of a typed shortcut input definition via reflection. It throws this error when the reflected Args type's Kind() is not reflect.Struct — e.g. a pointer to struct (*MyArgs), a map, or a slice was passed. The typed-input machinery requires a concrete non-pointer struct so it can enumerate fields with tags.","triggerScenarios":"Passing *MyArgs (pointer-to-struct), a map, slice, or interface type as the Args value of a typedInputDefinition, or registering a shortcut whose args generic parameter resolves to a non-struct kind.","commonSituations":"Declaring shortcuts with a pointer receiver-style Args type like &Config{} by habit; copying a definition that used a map[string]any for loose input; refactoring that changed a struct parameter to a pointer for 'optional' semantics.","solutions":["Change the Args type from a pointer (*T) to the plain struct value type T.","If the args are dynamic, use the loose/untyped input path instead of the typed compile path.","If Args is an alias to a non-struct type, define a real struct with flag/arg tags."],"exampleFix":"// before\nvar def = typedInputDefinition{ Args: reflect.TypeOf(&CreateTaskArgs{}) }\n// after\nvar def = typedInputDefinition{ Args: reflect.TypeOf(CreateTaskArgs{}) }","handlingStrategy":"validation","validationCode":"func validateArgsType(t reflect.Type) error {\n  if t == nil { return errors.New(\"Args type is nil\") }\n  if t.Kind() == reflect.Pointer { t = t.Elem() }\n  if t.Kind() != reflect.Struct {\n    return fmt.Errorf(\"Args must be a non-pointer struct, got %s\", t)\n  }\n  return nil\n}","typeGuard":"func isStructValue(v any) bool {\n  t := reflect.TypeOf(v)\n  return t != nil && t.Kind() == reflect.Struct\n}","tryCatchPattern":null,"preventionTips":["Always declare Args as a plain struct value type, never *T.","Add a unit test that compiles every shortcut definition at init or in CI.","Never pass map/slice-based arg containers to the typed input path."],"tags":["go","reflection","typed-input","developer-error"],"backgroundTag":"invalid-argument-value","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"}