{"record":{"id":"a69cb19fba235fe7","repo":"larksuite/cli","slug":"complex-input-requires-encoding","errorCode":null,"errorMessage":"complex input requires encoding","messagePattern":"complex input requires encoding","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shortcuts/common/typed_compile_args.go","lineNumber":308,"sourceCode":"\t}\n\tif len(field.cli.ValueSources) > 0 {\n\t\tif _, ok := seenSources[typedSourceFlag]; !ok {\n\t\t\treturn fmt.Errorf(\"ValueSources must include flag\")\n\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\")","sourceCodeStart":290,"sourceCodeEnd":326,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/shortcuts/common/typed_compile_args.go#L290-L326","documentation":"This is the switch-based counterpart to the explicit-declaration check: if field.cli.Encoding is empty and the indirect kind is a complex kind (slice, array, struct, map, interface), the field cannot be compiled. In practice the earlier check (line 301) rejects this first for complex kinds, so this branch guards the encoding switch invariant.","triggerScenarios":"An input field with a complex indirect kind and empty cli.Encoding reaching the encoding switch - i.e. a complex input with no encoding declared. Raised by compileInput during shortcut compilation.","commonSituations":"Same root cause as 'must explicitly declare CLI encoding': forgetting encoding=json/repeated/comma_or_repeated on a slice/struct/map/interface field; constructing InputField structs programmatically and leaving Encoding zero-valued.","solutions":["Set an explicit encoding (json, repeated, or comma_or_repeated) matching the field's type","Make the field type scalar (string/int/bool) so encoding is unnecessary","Verify the cli tag string actually includes the encoding segment (spelling: encoding=json)"],"exampleFix":"// before\nCLI{Flag: \"payload\"} // struct field, Encoding \"\"\n// after\nCLI{Flag: \"payload\", Encoding: \"json\"}","handlingStrategy":"validation","validationCode":"// same guard as 625: complex kinds must not reach the encoding switch with Encoding == \"\"\nif needsEncoding(fieldType) && cli.Encoding == \"\" {\n\treturn errors.New(\"set encoding before compiling\")\n}","typeGuard":null,"tryCatchPattern":"if err := compileInput(...); err != nil {\n\tif strings.Contains(err.Error(), \"complex input requires encoding\") {\n\t\t// assign an explicit encoding and recompile\n\t}\n\treturn err\n}","preventionTips":["Never leave Encoding zero-valued when constructing InputField structs for complex types","Prefer typed helper constructors that force an encoding for complex inputs","Catch this in unit tests via TestParseCLITagRejectsInvalidGrammar-style cases"],"tags":["cli","shortcut-input","encoding","complex-types"],"backgroundTag":"cli-input-encoding-required","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"}