{"record":{"id":"02c3397a0952c8b1","repo":"hashicorp/terraform","slug":"expected-a-single-argument-name-02c339","errorCode":null,"errorMessage":"Expected a single argument: NAME.","messagePattern":"Expected a single argument: NAME\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/command/arguments/workspace_select.go","lineNumber":45,"sourceCode":"func ParseWorkspaceSelect(args []string) (*WorkspaceSelect, tfdiags.Diagnostics) {\n\tvar diags tfdiags.Diagnostics\n\n\tvar orCreate bool\n\tcmdFlags := defaultFlagSet(\"workspace select\")\n\tcmdFlags.BoolVar(&orCreate, \"or-create\", false, \"create workspace if it does not exist\")\n\tif err := cmdFlags.Parse(args); err != nil {\n\t\tdiags = diags.Append(tfdiags.Sourceless(\n\t\t\ttfdiags.Error,\n\t\t\t\"Failed to parse command-line flags\",\n\t\t\terr.Error(),\n\t\t))\n\t}\n\n\t// `workspace select` takes only one positional argument: workspace name.\n\targs = cmdFlags.Args()\n\tvar name string\n\tif len(args) == 0 {\n\t\tdiags = diags.Append(errors.New(\"Expected a single argument: NAME.\")) // Recreating pre-existing error from command package\n\t} else {\n\t\t// Obtain and validate name argument.\n\t\tname = args[0]\n\t\tif !ValidWorkspaceName(name) {\n\t\t\tdiags = diags.Append(fmt.Errorf(EnvInvalidName, name))\n\t\t}\n\n\t\t// Checking for extra arguments here, not with a len != 1 check above, allows the name to be returned\n\t\targs = args[1:]\n\t\tif len(args) != 0 {\n\t\t\tdiags = diags.Append(errors.New(\"Expected a single argument: NAME.\"))\n\t\t}\n\t}\n\n\treturn &WorkspaceSelect{\n\t\tWorkspace: Workspace{ViewType: ViewHuman},\n\t\tOrCreate:  orCreate,\n\t\tName:      name,","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/hashicorp/terraform/blob/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/command/arguments/workspace_select.go#L27-L63","documentation":"Returned at workspace_select.go:45 when 'terraform workspace select' is invoked with zero positional arguments. The command requires exactly one positional argument: the workspace NAME. workspace_select.go:43-44 checks 'len(args) == 0' after flag parsing.","triggerScenarios":"Running 'terraform workspace select' with no workspace name, or providing only flags. workspace_select.go:43 checks 'len(args) == 0'.","commonSituations":"Forgetting the workspace name; shell scripts with empty variables; assuming 'select' without arguments defaults to something.","solutions":["Provide the workspace name: 'terraform workspace select <workspace-name>'.","Run 'terraform workspace list' to see available workspace names.","Check scripts for empty or unquoted variables."],"exampleFix":"// before\nterraform workspace select\n// error: Expected a single argument: NAME.\n\n// after\nterraform workspace select my-workspace","handlingStrategy":"validation","validationCode":"// Validate workspace name is provided before calling workspace select:\n// if name == \"\" {\n//     return fmt.Errorf(\"workspace name is required for select\")\n// }\n// exec.Command(\"terraform\", \"workspace\", \"select\", name)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass a workspace name to 'terraform workspace select'.","List available workspaces first if unsure of the name.","Validate variables in scripts are non-empty before use."],"tags":["terraform","cli","workspace","argument-validation"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}