{"record":{"id":"422da272a09c2edc","repo":"larksuite/cli","slug":"encoding-repeated-requires-an-array-or-slice","errorCode":null,"errorMessage":"encoding repeated requires an array or slice","messagePattern":"encoding repeated requires an array or slice","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shortcuts/common/typed_compile_args.go","lineNumber":312,"sourceCode":"\t\t}\n\t\tif (len(seenSources) > 1) && indirectKind(field.valueType) != reflect.String && field.cli.Encoding != typedEncodingJSON {\n\t\t\treturn fmt.Errorf(\"file/stdin sources require string input or encoding=json\")\n\t\t}\n\t}\n\tkind := indirectKind(field.valueType)\n\tif kind == reflect.Slice || kind == reflect.Array || kind == reflect.Struct || kind == reflect.Map || kind == reflect.Interface {\n\t\tif field.cli.Encoding == \"\" {\n\t\t\treturn fmt.Errorf(\"%s input must explicitly declare CLI encoding\", kind)\n\t\t}\n\t}\n\tswitch field.cli.Encoding {\n\tcase \"\":\n\t\tif kind == reflect.Slice || kind == reflect.Array || kind == reflect.Struct || kind == reflect.Map || kind == reflect.Interface {\n\t\t\treturn fmt.Errorf(\"complex input requires encoding\")\n\t\t}\n\tcase typedEncodingRepeated:\n\t\tif kind != reflect.Slice && kind != reflect.Array {\n\t\t\treturn fmt.Errorf(\"encoding repeated requires an array or slice\")\n\t\t}\n\t\tif indirectType(field.valueType).Elem().Kind() != reflect.String {\n\t\t\treturn fmt.Errorf(\"encoding repeated only supports string arrays\")\n\t\t}\n\t\tif field.nullable != nil {\n\t\t\treturn fmt.Errorf(\"encoding repeated does not allow nullable/nonnullable\")\n\t\t}\n\tcase typedEncodingCommaOrRepeated:\n\t\tif kind != reflect.Slice && kind != reflect.Array {\n\t\t\treturn fmt.Errorf(\"encoding comma_or_repeated requires an array or slice\")\n\t\t}\n\t\telementKind := indirectType(field.valueType).Elem().Kind()\n\t\tif elementKind != reflect.String && !isIntegerKind(elementKind) {\n\t\t\treturn fmt.Errorf(\"encoding comma_or_repeated only supports string or integer arrays\")\n\t\t}\n\t\tif field.nullable != nil {\n\t\t\treturn fmt.Errorf(\"encoding comma_or_repeated does not allow nullable/nonnullable\")\n\t\t}","sourceCodeStart":294,"sourceCodeEnd":330,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/shortcuts/common/typed_compile_args.go#L294-L330","documentation":"The repeated encoding means the flag may be supplied multiple times, one value per occurrence; that model only makes sense for Go slices or arrays. validateInputCLI rejects encoding=repeated on any other kind (scalar, struct, map, interface) with this message.","triggerScenarios":"Declaring an input field with Encoding \"repeated\" whose valueType is not a slice or array - e.g. a string, int, or struct field. Raised by compileInput during shortcut compilation.","commonSituations":"Copying the encoding=repeated fragment from a []string field onto a scalar field; wanting comma-separated parsing (which is comma_or_repeated, not repeated) but selecting repeated; refactoring a field's type from []string to string without dropping the encoding.","solutions":["Change the field type to []string (or an array) to keep encoding repeated","Switch the encoding to comma_or_repeated if you want a single comma-separated value or repeated occurrences for string/integer arrays","Remove the encoding if the field is scalar and should be set once"],"exampleFix":"// before\ncli:\"--name,encoding=repeated\" // string field\n// after\ncli:\"--name\" // scalar set once, or []string with encoding=repeated","handlingStrategy":"validation","validationCode":"func repeatedEncodingOK(t reflect.Type) bool {\n\tfor t.Kind() == reflect.Ptr {\n\t\tt = t.Elem()\n\t}\n\treturn t.Kind() == reflect.Slice || t.Kind() == reflect.Array\n}","typeGuard":null,"tryCatchPattern":"if err := compileInput(...); err != nil {\n\tif strings.Contains(err.Error(), \"encoding repeated requires\") {\n\t\t// change the field to []string or drop encoding=repeated\n\t}\n\treturn err\n}","preventionTips":["Use encoding=repeated only for []string fields","Use comma_or_repeated for single-occurrence comma-separated values","Grep for encoding=repeated when changing a field's type"],"tags":["cli","shortcut-input","encoding","repeated"],"backgroundTag":"cli-encoding-type-mismatch","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"}