{"record":{"id":"320d4051a0bff579","repo":"larksuite/cli","slug":"file-stdin-sources-require-string-input-or-encodin","errorCode":null,"errorMessage":"file/stdin sources require string input or encoding=json","messagePattern":"file/stdin sources require string input or encoding=json","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shortcuts/common/typed_compile_args.go","lineNumber":296,"sourceCode":"\t\t\treturn fmt.Errorf(\"default: %w\", err)\n\t\t}\n\t}\n\tseenSources := make(map[typedValueSource]struct{})\n\tfor _, source := range field.cli.ValueSources {\n\t\tif source != typedSourceFlag && source != typedSourceFile && source != typedSourceStdin {\n\t\t\treturn fmt.Errorf(\"unknown value source %q\", source)\n\t\t}\n\t\tif _, duplicate := seenSources[source]; duplicate {\n\t\t\treturn fmt.Errorf(\"duplicate value source %q\", source)\n\t\t}\n\t\tseenSources[source] = struct{}{}\n\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 {","sourceCodeStart":278,"sourceCodeEnd":314,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/shortcuts/common/typed_compile_args.go#L278-L314","documentation":"file/stdin values arrive as raw text, so a field combining multiple sources must either have a string value type or use encoding=json to parse the text into a complex value. validateInputCLI enforces this when len(seenSources) > 1: if the indirect kind is not reflect.String and CLI.Encoding is not json, the text cannot be safely converted.","triggerScenarios":"Declaring ValueSources with more than one source (e.g. [flag, file]) on a field whose valueType is int, bool, a slice, or a struct while leaving encoding unset or non-json. Raised by compileInput during shortcut compilation.","commonSituations":"Adding a file source to an integer or boolean input assuming the raw text will be coerced; adding file/stdin to a slice field without setting encoding=json; mixing an @file-style convenience with typed non-string inputs.","solutions":["Set Encoding: \"json\" in the cli tag so file/stdin text is parsed as JSON into the target type","Change the field's value type to string if raw text is what you want","Drop the file/stdin sources if the typed non-string field should only come from a flag"],"exampleFix":"// before\nValueSources: []string{\"flag\", \"file\"} // int field, no encoding\n// after\nValueSources: []string{\"flag\", \"file\"}\nEncoding: \"json\" // or change the field to a string type","handlingStrategy":"validation","validationCode":"func multiSourceOK(kind reflect.Kind, enc string) bool {\n\treturn kind == reflect.String || enc == \"json\"\n}\n// check before enabling file/stdin sources on a non-string field","typeGuard":null,"tryCatchPattern":"if err := compileInput(...); err != nil {\n\tif strings.Contains(err.Error(), \"file/stdin sources require\") {\n\t\t// set encoding=json or change the type to string\n\t}\n\treturn err\n}","preventionTips":["Only add file/stdin sources to string or encoding=json fields","For complex types with file input, always pair encoding=json with the extra sources","Test file-source behavior with a dry-run E2E when adding sources"],"tags":["cli","shortcut-input","value-sources","encoding"],"backgroundTag":"cli-encoding-source-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"}