{"record":{"id":"7c044f68c9514777","repo":"grafana/k6","slug":"secret-source-for-name-q-already-registered-befor","errorCode":null,"errorMessage":"secret source for name %q already registered before configuration %q","messagePattern":"secret source for name %q already registered before configuration %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cmd/root.go","lineNumber":531,"sourceCode":"\t\tif !ok {\n\t\t\treturn nil, fmt.Errorf(\"no secret source for type %q for configuration %q\", t, line)\n\t\t}\n\t\tc := found.Module.(secretsource.Constructor) //nolint:forcetypeassert\n\t\tparams := baseParams\n\t\tname, isDefault, config := extractNameAndDefault(config)\n\t\tif name == \"\" {\n\t\t\t// Default the name to the source type to avoid an empty-string key.\n\t\t\tname = t\n\t\t}\n\t\tparams.ConfigArgument = config\n\n\t\tsecretSource, err := c(params)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\t_, alreadRegistered := result[name]\n\t\tif alreadRegistered {\n\t\t\treturn nil, fmt.Errorf(\"secret source for name %q already registered before configuration %q\", t, line)\n\t\t}\n\t\tresult[name] = secretSource\n\t\tif isDefault {\n\t\t\tif _, ok := result[\"default\"]; ok {\n\t\t\t\treturn nil, fmt.Errorf(\"can't have two secret sources that are default ones, second one was %q\", config)\n\t\t\t}\n\t\t\tresult[\"default\"] = secretSource\n\t\t}\n\t}\n\n\tif len(result) == 1 {\n\t\tfor _, l := range result {\n\t\t\tresult[\"default\"] = l\n\t\t}\n\t}\n\n\t// Capture the cloud source instance if it was registered (via local-execution auto-injection\n\t// or the env-var path below), so createCloudTest can call SetConfig on it later.","sourceCodeStart":513,"sourceCodeEnd":549,"githubUrl":"https://github.com/grafana/k6/blob/8d06114777191d21ef885d05c5f8aa9e1ed838ae/internal/cmd/root.go#L513-L549","documentation":"Every secret source gets a name: taken from the name=... key inside its comma-separated config, otherwise defaulting to the source type. Two --secret-source entries resolving to the same name make the second registration fail. Note the message prints the source TYPE (the first %q is the type) along with the full second configuration line.","triggerScenarios":"--secret-source=file=a.txt --secret-source=file=b.txt (both default to name 'file'); or two entries with the same explicit name, e.g. --secret-source=file,name=x=... --secret-source=mock,name=x=...","commonSituations":"Wanting two files as secret sources without naming them; copy-pasting a --secret-source line and editing only the path; migrating a shared config to multiple sources.","solutions":["Give each source a unique name: --secret-source=file,name=a=a.txt --secret-source=file,name=b=b.txt","If you only need one source of that type, delete the duplicate entry","Check every name= key across all entries — names must be unique"],"exampleFix":"# before\nk6 run --secret-source=file=a.txt --secret-source=file=b.txt script.js\n\n# after\nk6 run --secret-source=file,name=a=a.txt --secret-source=file,name=b=b.txt script.js","handlingStrategy":"validation","validationCode":"# collect source names (name= key or the type) and reject duplicates before running\ncheck_names() {\n  declare -A seen\n  for entry in \"$@\"; do\n    type=\"${entry%%=*}\"; config=\"${entry#*=}\"\n    name=\"$type\"\n    for kv in ${config//,/ }; do [ \"${kv%%=*}\" = name ] && name=\"${kv#*=}\"; done\n    [ -n \"${seen[$name]:-}\" ] && { echo \"duplicate secret source name: $name\" >&2; return 1; }\n    seen[$name]=1\n  done\n}\ncheck_names \"file=a.txt\" \"file,name=b=b.txt\" || exit 1","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always set an explicit name= when configuring more than one source of the same type","Keep secret-source entries in a single, reviewable list rather than scattering them across scripts","Remember the un-named default is the type itself — two type-only 'file' entries will always collide"],"tags":["k6","secrets","secret-source","duplicate","config"],"backgroundTag":"duplicate-config-entry","analyzedSha":"8d06114777191d21ef885d05c5f8aa9e1ed838ae","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":"2026-08-18T03:05:52.393Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}