{"record":{"id":"c0eb5978f5fccdf8","repo":"wavetermdev/waveterm","slug":"secret-name-cannot-be-empty","errorCode":null,"errorMessage":"secret name cannot be empty","messagePattern":"secret name cannot be empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/wsh/cmd/wshcmd-secret.go","lineNumber":116,"sourceCode":"\tWriteStdout(\"%s\\n\", value)\n\treturn nil\n}\n\nfunc secretSetRun(cmd *cobra.Command, args []string) (rtnErr error) {\n\tdefer func() {\n\t\tsendActivity(\"secret\", rtnErr == nil)\n\t}()\n\n\tparts := strings.SplitN(args[0], \"=\", 2)\n\tif len(parts) != 2 {\n\t\treturn fmt.Errorf(\"invalid format: expected [name]=[value]\")\n\t}\n\n\tname := parts[0]\n\tvalue := parts[1]\n\n\tif name == \"\" {\n\t\treturn fmt.Errorf(\"secret name cannot be empty\")\n\t}\n\n\tbackend, err := wshclient.GetSecretsLinuxStorageBackendCommand(RpcClient, &wshrpc.RpcOpts{Timeout: 2000})\n\tif err != nil {\n\t\treturn fmt.Errorf(\"checking secret storage backend: %w\", err)\n\t}\n\n\tif backend == \"basic_text\" || backend == \"unknown\" {\n\t\treturn fmt.Errorf(\"No appropriate secret manager found, cannot set secrets\")\n\t}\n\n\tsecrets := map[string]*string{name: &value}\n\terr = wshclient.SetSecretsCommand(RpcClient, secrets, &wshrpc.RpcOpts{Timeout: 2000})\n\tif err != nil {\n\t\treturn fmt.Errorf(\"setting secret: %w\", err)\n\t}\n\n\tWriteStdout(\"secret set: %s\\n\", name)","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/cmd/wsh/cmd/wshcmd-secret.go#L98-L134","documentation":"After splitting the NAME=VALUE argument, `wsh secret set` explicitly rejects an empty name portion. This guards against inputs like \"=value\" or \"=\", which would otherwise create a nameless secret entry. The value may legitimately be empty, but the name may not.","triggerScenarios":"Running `wsh secret set =myvalue` or `wsh secret set \"=\"` — usually the result of an unquoted/empty shell variable interpolated into the argument: `wsh secret set \"$KEY=$VAL\"` where $KEY is unset.","commonSituations":"CI/shell scripts with unset environment variables (set -u not enabled); loops reading key=value pairs where blank lines produce empty keys; mis-templated config generation.","solutions":["Supply a valid name: `wsh secret set mykey=myvalue`.","Check the variable holding the key name is non-empty before invoking: `[ -n \"$KEY\" ] || exit 1` or use `set -u` in shell scripts.","Trim whitespace/newlines from the key variable (e.g. KEY=$(echo \"$KEY\" | tr -d '[:space:]')) since stray whitespace can produce unexpected names.","Enable shell strict mode (`set -euo pipefail`) so unset KEY variables fail the script before reaching wsh."],"exampleFix":"// before\nwsh secret set \"$KEY=$VALUE\"   # KEY empty -> '=value'\n// after\n: \"${KEY:?KEY must be set}\"\nwsh secret set \"${KEY}=${VALUE}\"","handlingStrategy":"validation","validationCode":"name, value, found := strings.Cut(arg, \"=\")\nif !found || strings.TrimSpace(name) == \"\" {\n    return fmt.Errorf(\"secret name cannot be empty in %q\", arg)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use set -u / ${KEY:?} guards so unset variables fail before invoking wsh","Trim whitespace from variables that hold key names","Validate the split parts in wrapper scripts before calling wsh","Never interpolate possibly-empty variables unquoted into the argument"],"tags":["cli","validation","shell-scripting"],"backgroundTag":"empty-required-argument","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}