{"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/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/command/arguments/workspace_delete.go#L44-L80","documentation":"Thrown by terraform workspace delete when the NAME positional argument is provided but is an empty string. Terraform explicitly checks args[0]==\"\" separately from the missing-argument check to give a clearer error than a generic 'expected one argument' message.","triggerScenarios":"Running terraform workspace delete \"\" or passing an empty-string argument. The name==\"\" check triggers after confirming at least one argument was provided but before checking for extra arguments.","commonSituations":"Shell variable expansion producing an empty string (e.g., terraform workspace delete \"$WS_NAME\" where WS_NAME is unset or empty); quoting errors in scripts; automated tooling or wrappers passing an empty workspace name.","solutions":["Check that the workspace name variable is set and non-empty before invoking the command","Use shell parameter expansion with a guard: terraform workspace delete \"${WS_NAME:?workspace name required}\"","Verify the argument is passed correctly by echoing it before the command: echo \"[$WS_NAME]\""],"exampleFix":"# before\nWS_NAME=\"\"\nterraform workspace delete \"$WS_NAME\"\n\n# after\nWS_NAME=\"dev\"\nterraform workspace delete \"$WS_NAME\"","handlingStrategy":"validation","validationCode":"// Validate workspace name argument before calling terraform workspace delete\nfunc validateWorkspaceNameArg(name string) error {\n    if name == \"\" {\n        return errors.New(\"workspace name must not be empty\")\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always check shell variables are set and non-empty before passing as workspace name","Use ${VAR:?error message} shell expansion to fail fast on empty variables","Validate workspace names in automation scripts before invoking terraform","Echo bracketed variables in debug output to catch empty strings: echo \"[$WS_NAME]\""],"tags":["workspace","cli-args","validation","empty-string"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}