{"record":{"id":"be354295f38283c2","repo":"hashicorp/terraform","slug":"empty-state-name","errorCode":null,"errorMessage":"empty state name","messagePattern":"empty state name","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/backend/local/backend.go","lineNumber":244,"sourceCode":"\tsort.Strings(listed)\n\tenvs = append(envs, listed...)\n\n\treturn envs, diags\n}\n\n// DeleteWorkspace removes a workspace.\n//\n// The \"default\" workspace cannot be removed.\nfunc (b *Local) DeleteWorkspace(name string, force bool) tfdiags.Diagnostics {\n\tvar diags tfdiags.Diagnostics\n\n\t// If we have a backend handling state, defer to that.\n\tif b.Backend != nil {\n\t\treturn b.Backend.DeleteWorkspace(name, force)\n\t}\n\n\tif name == \"\" {\n\t\treturn diags.Append(errors.New(\"empty state name\"))\n\t}\n\n\tif name == backend.DefaultStateName {\n\t\treturn diags.Append(errors.New(\"cannot delete default state\"))\n\t}\n\n\tdelete(b.states, name)\n\terr := os.RemoveAll(filepath.Join(b.stateWorkspaceDir(), name))\n\tif err != nil {\n\t\treturn diags.Append(fmt.Errorf(\"error deleting workspace %s: %w\", name, err))\n\t}\n\n\treturn diags\n}\n\nfunc (b *Local) StateMgr(name string) (statemgr.Full, tfdiags.Diagnostics) {\n\tvar diags tfdiags.Diagnostics\n","sourceCodeStart":226,"sourceCodeEnd":262,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/backend/local/backend.go#L226-L262","documentation":"Returned by Local.DeleteWorkspace (internal/backend/local/backend.go:244) when the provided workspace name is the empty string. The local backend refuses to delete a workspace with no name because there is nothing to target and it would be a programming error rather than a user action.","triggerScenarios":"Calling (*Local).DeleteWorkspace(\"\", force) directly; CLI/frontend code that passes an unset/empty workspace variable (e.g. a missing TF_WORKSPACE or an unconfigured current workspace) into DeleteWorkspace.","commonSituations":"Bugs in wrappers/automation that fail to resolve the current workspace before calling DeleteWorkspace; scripts that read the workspace from a config/env var that was never set and pass the zero value.","solutions":["Resolve and pass a non-empty workspace name to DeleteWorkspace.","Validate that the workspace name is non-empty before calling the API (guard at the call site).","If the empty name comes from env/config, fix the configuration so the workspace is always defined."],"exampleFix":"// before\nb.DeleteWorkspace(ws, false) // ws may be \"\"\n\n// after\nif ws == \"\" {\n    return fmt.Errorf(\"cannot delete workspace: name is empty\")\n}\nb.DeleteWorkspace(ws, false)","handlingStrategy":"validation","validationCode":"if name == \"\" {\n    return fmt.Errorf(\"cannot delete workspace: name is empty\")\n}\nb.DeleteWorkspace(name, force)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always validate the workspace name is non-empty before calling DeleteWorkspace.","Resolve the current workspace from config/env at a single chokepoint rather than at each call site.","Default unresolved workspace values to backend.DefaultStateName."],"tags":["backend","local","workspace","validation"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}