{"record":{"id":"9c65eee7c2102c4b","repo":"larksuite/cli","slug":"duplicate-value-source-q","errorCode":null,"errorMessage":"duplicate value source %q","messagePattern":"duplicate value source %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shortcuts/common/typed_compile_args.go","lineNumber":287,"sourceCode":"func validateInputCLI(field *compiledInputField) error {\n\tif field.cli.Deprecated != \"\" && !field.cli.Hidden {\n\t\treturn fmt.Errorf(\"deprecated primary flag must be hidden\")\n\t}\n\tif field.required && field.defaultValue.Set {\n\t\treturn fmt.Errorf(\"required input cannot declare a default\")\n\t}\n\tif field.defaultValue.Set {\n\t\tif err := valueAssignableTo(field.defaultValue.Value, field.valueType); err != nil {\n\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 {","sourceCodeStart":269,"sourceCodeEnd":305,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/shortcuts/common/typed_compile_args.go#L269-L305","documentation":"ValueSources must be unique per input field; validateInputCLI tracks sources in a seenSources set and rejects any source appearing twice. Duplicates are meaningless (a source either contributes a value or not) and usually indicate a copy/paste or merge mistake.","triggerScenarios":"Listing the same source twice in ValueSources, e.g. [flag, file, file] or [flag, stdin, stdin], via the cli tag or InputField.CLI. Raised by compileInput during shortcut compilation.","commonSituations":"Appending a source to a list that already contained it; merging two field declarations and concatenating their ValueSources; generating the tag from code with a loop bug.","solutions":["Deduplicate the ValueSources list, keeping each of flag/file/stdin at most once","Review where the tag is constructed to remove the duplication (e.g. use a set before building the slice)","Remove the extra entry if it was added by mistake"],"exampleFix":"// before\nValueSources: []string{\"flag\", \"file\", \"file\"}\n// after\nValueSources: []string{\"flag\", \"file\"}","handlingStrategy":"validation","validationCode":"func dedupe(srcs []string) []string {\n\tseen := map[string]bool{}\n\tout := srcs[:0]\n\tfor _, s := range srcs {\n\t\tif !seen[s] {\n\t\t\tseen[s] = true\n\t\t\tout = append(out, s)\n\t\t}\n\t}\n\treturn out\n}","typeGuard":null,"tryCatchPattern":"if err := compileInput(...); err != nil {\n\tif strings.Contains(err.Error(), \"duplicate value source\") {\n\t\t// deduplicate ValueSources and recompile\n\t}\n\treturn err\n}","preventionTips":["Treat ValueSources as a set, not a list, when generating them programmatically","Review merge diffs for concatenated ValueSources lists","Keep at most three entries: flag, file, stdin"],"tags":["cli","shortcut-input","value-sources","duplicate"],"backgroundTag":"cli-invalid-value-source","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"}