{"record":{"id":"de6c5e45376fed63","repo":"larksuite/cli","slug":"encoding-comma-or-repeated-requires-an-array-or-sl","errorCode":null,"errorMessage":"encoding comma_or_repeated requires an array or slice","messagePattern":"encoding comma_or_repeated requires an array or slice","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shortcuts/common/typed_compile_args.go","lineNumber":322,"sourceCode":"\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}\n\tcase typedEncodingJSON:\n\t\tif kind != reflect.Slice && kind != reflect.Array && kind != reflect.Struct && kind != reflect.Map && kind != reflect.Interface {\n\t\t\treturn fmt.Errorf(\"encoding json requires array, object, oneOf, or custom JSON input\")\n\t\t}\n\t\tif isNilCapable(field.valueType) && field.nullable == nil && !field.shapeExplicit && !shapeExplicitlyNullable(field.shape) {\n\t\t\treturn fmt.Errorf(\"nil-capable encoding=json input must declare nullable or nonnullable\")\n\t\t}\n\tdefault:\n\t\treturn fmt.Errorf(\"unknown CLI encoding %q\", field.cli.Encoding)\n\t}","sourceCodeStart":304,"sourceCodeEnd":340,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/shortcuts/common/typed_compile_args.go#L304-L340","documentation":"validateInputCLI checks each typed input field declared via `cli` tags or InputField.CLI when a shortcut compiles its input struct (compileInput). The `encoding=comma_or_repeated` encoding accepts a CLI value as either a comma-separated list or repeated flags, which only makes sense for array/slice fields. This error means the field carrying that encoding is not a slice or array.","triggerScenarios":"A shortcut input struct declares a non-array field (e.g. `string`, `int`, `map[string]string`) with tag `cli:\"encoding=comma_or_repeated\"` or sets InputField.CLI.Encoding = \"comma_or_repeated\"; compileInput then calls validateInputCLI and fails.","commonSituations":"Copy-pasting a tag from a list-typed field onto a scalar field; renaming a field's Go type from []string to string without removing the encoding; hand-writing InputField.CLI metadata to match another field's encoding.","solutions":["Change the field type to a slice or array (e.g. []string or []int) to match encoding=comma_or_repeated.","If the field is truly scalar, drop the encoding (plain strings need no encoding) or use a supported encoding for its type.","Check mergeInputSupplement: the encoding may come from InputField.CLI rather than the tag; remove it from whichever source is wrong."],"exampleFix":"// before\nNames string `schema:\"optional\" cli:\"encoding=comma_or_repeated\"`\n// after\nNames []string `schema:\"optional\" cli:\"encoding=comma_or_repeated\"`","handlingStrategy":"validation","validationCode":"func validCommaOrRepeatedEncoding(v any) error {\n\tt := reflect.TypeOf(v)\n\tfor t != nil && (t.Kind() == reflect.Ptr) { t = t.Elem() }\n\tif t == nil || (t.Kind() != reflect.Slice && t.Kind() != reflect.Array) {\n\t\treturn fmt.Errorf(\"comma_or_repeated needs slice/array, got %v\", t)\n\t}\n\treturn nil\n}","typeGuard":"func isSliceOrArray(t reflect.Type) bool {\n\tfor t != nil && t.Kind() == reflect.Ptr { t = t.Elem() }\n\treturn t != nil && (t.Kind() == reflect.Slice || t.Kind() == reflect.Array)\n}","tryCatchPattern":null,"preventionTips":["Keep encoding tags only on slice/array fields; grep `encoding=comma_or_repeated` in reviews.","When changing a field's Go type, re-check its cli tag in the same commit.","Add a unit test that compiles every shortcut input struct so compileInput failures surface in CI."],"tags":["cli","schema","type-mismatch","authoring-time"],"backgroundTag":"invalid-cli-tag-encoding","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"}