{"record":{"id":"2f9d6ce9bc32096c","repo":"hashicorp/terraform","slug":"expected-a-workspace-name-as-an-argument-instead","errorCode":null,"errorMessage":"Expected a workspace name as an argument, instead got an empty string: %q\n","messagePattern":"Expected a workspace name as an argument, instead got an empty string: %q\n","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/command/arguments/workspace_delete.go","lineNumber":62,"sourceCode":"\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}\n\n\treturn &WorkspaceDelete{\n\t\tWorkspace:   Workspace{ViewType: ViewHuman},\n\t\tName:        name,\n\t\tLock:        stateLock,\n\t\tLockTimeout: stateLockTimeout,\n\t\tForce:       force,\n\t}, diags\n}\n","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/command/arguments/workspace_delete.go#L44-L80","documentation":"Emitted by `terraform workspace delete` (workspace_delete.go:62) when exactly one positional argument is supplied but it is the empty string. Note the separate path at workspace_delete.go:51-52 covers the no-argument case; this error is specifically `len(args) >= 1 && args[0] == \"\"`. `workspace delete` intentionally does NOT run `ValidWorkspaceName` so users can remove workspaces with unusual names, but it still rejects an empty name.","triggerScenarios":"Running `terraform workspace delete \"\"` (an explicitly empty argument), e.g. via a shell where a variable expanded to empty: `terraform workspace delete \"$WS\"` with `WS` unset/empty.","commonSituations":"Shell scripts that pass an unset environment variable as the workspace name; CI matrices that emit an empty name for the default branch; quoting mistakes that pass an empty token.","solutions":["Pass a non-empty workspace name: `terraform workspace delete <name>`.","In scripts, guard the variable before calling: only run when the name is non-empty.","If you meant the default workspace, delete the target's resources instead — the `default` workspace cannot be deleted."],"exampleFix":"# before\nWS=\"\"\nterraform delete \"$WS\"   # or: terraform workspace delete \"\"\n# Expected a workspace name as an argument, instead got an empty string: \"\"\n\n# after (guard in shell)\nWS=\"${WS:?workspace name required}\"\nterraform workspace delete \"$WS\"","handlingStrategy":"validation","validationCode":"// Validate a workspace name before calling 'terraform workspace delete'.\nfunc deleteWorkspaceArg(name string) error {\n    if name == \"\" {\n        return fmt.Errorf(\"workspace name must not be empty\")\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["In shell scripts, use `${WS:?workspace name required}` to fail fast on empty.","Separate the no-arg case from the empty-string-arg case when scripting workspace deletion.","Remember `delete` deliberately skips full name validation, so callers must sanitize."],"tags":["terraform","workspace","delete","arguments","validation"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}