{"record":{"id":"c22d6007486dacea","repo":"hashicorp/terraform","slug":"expected-a-single-argument-name","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_delete.go","lineNumber":52,"sourceCode":"\tvar stateLock bool\n\tvar stateLockTimeout time.Duration\n\tcmdFlags := defaultFlagSet(\"workspace delete\")\n\tcmdFlags.BoolVar(&force, \"force\", false, \"force removal of a non-empty workspace\")\n\tcmdFlags.BoolVar(&stateLock, \"lock\", true, \"lock state\")\n\tcmdFlags.DurationVar(&stateLockTimeout, \"lock-timeout\", 0, \"lock timeout\")\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 delete` 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\n\t\t// Obtain and validate name argument\n\t\t//\n\t\t// We purposefully don't use ValidWorkspaceName here; if a user\n\t\t// creates a workspace with an invalid name they should be able to\n\t\t// delete it easily.\n\t\tname = args[0]\n\t\tif name == \"\" {\n\t\t\tdiags = diags.Append(fmt.Errorf(\"Expected a workspace name as an argument, instead got an empty string: %q\\n\", args[0]))\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}","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/hashicorp/terraform/blob/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/command/arguments/workspace_delete.go#L34-L70","documentation":"Returned at workspace_delete.go:52 when 'terraform workspace delete' is invoked with zero positional arguments after flag parsing. The command requires exactly one positional argument: the workspace NAME. This is a CLI argument validation error appended to diagnostics.","triggerScenarios":"Running 'terraform workspace delete' with no workspace name argument, or providing only flags (e.g., 'terraform workspace delete -force' with no name). workspace_delete.go:50 checks 'len(args) == 0' after cmdFlags.Args().","commonSituations":"Typing 'terraform workspace delete' and forgetting the name; shell scripts that pass an empty variable as the workspace name; copy-paste errors omitting the workspace argument.","solutions":["Provide the workspace name: 'terraform workspace delete <workspace-name>'.","Check shell scripts for unquoted or empty variables passed as the workspace name.","Run 'terraform workspace list' to see available workspace names."],"exampleFix":"// before\nterraform workspace delete\n// error: Expected a single argument: NAME.\n\n// after\nterraform workspace delete my-workspace","handlingStrategy":"validation","validationCode":"// Before calling workspace delete, validate the name is provided:\n// if name == \"\" {\n//     return fmt.Errorf(\"workspace name is required\")\n// }\n// exec.Command(\"terraform\", \"workspace\", \"delete\", name)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate workspace name is non-empty before passing to terraform CLI.","Use shell scripts that check for required arguments before invoking terraform.","Provide argument help text in wrapper scripts."],"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"}