{"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/c9def3e214014c1188faabfc4a5bde5095139765/internal/command/arguments/workspace_delete.go#L34-L70","documentation":"Returned by ParseWorkspaceDelete (workspace_delete.go:52) when, after flag parsing, zero positional arguments remain — i.e. the user ran 'terraform workspace delete' with no NAME. The command requires exactly one workspace name to delete. ParseWorkspaceDelete still returns a WorkspaceDelete with an empty Name and the diagnostics, so the caller can choose how to surface it.","triggerScenarios":"Line 49-52: cmdFlags.Args() returns len(args)==0, so errors.New(\"Expected a single argument: NAME.\") is appended to diags.","commonSituations":"Typing 'terraform workspace delete' without a name; a script that interpolates a variable which expands to empty; alias confusion with 'terraform delete'.","solutions":["Provide the workspace name: 'terraform workspace delete NAME'.","List workspaces first with 'terraform workspace list' to get the exact name.","If scripting, validate the name variable is non-empty before invoking the command."],"exampleFix":"# before\n$ terraform workspace delete\n# after\n$ terraform workspace delete my-old-workspace","handlingStrategy":"validation","validationCode":"// Validate delete args before invoking the CLI/parser.\nfunc validateDeleteName(args []string) error {\n    if len(args) == 0 {\n        return errors.New(\"workspace delete requires a NAME argument\")\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass an explicit workspace name to 'terraform workspace delete'.","In scripts, fail fast if the name variable is empty before calling Terraform.","Use 'terraform workspace list' to confirm names before deletion."],"tags":["cli-arguments","workspace","delete","missing-argument"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T20:17:04.800Z"}