{"record":{"id":"85e15248598d680f","repo":"hashicorp/terraform","slug":"error-deleting-workspace-s-w","errorCode":null,"errorMessage":"error deleting workspace %s: %w","messagePattern":"error deleting workspace (.+?): %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/backend/local/backend.go","lineNumber":254,"sourceCode":"\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\n\t// If we have a backend handling state, delegate to that.\n\tif b.Backend != nil {\n\t\treturn b.Backend.StateMgr(name)\n\t}\n\n\tif s, ok := b.states[name]; ok {\n\t\treturn s, diags\n\t}\n\n\tif err := b.createState(name); err != nil {","sourceCodeStart":236,"sourceCodeEnd":272,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/backend/local/backend.go#L236-L272","documentation":"Returned by Local.DeleteWorkspace when os.RemoveAll fails to remove the workspace's state directory on disk. The workspace name is included; the wrapped error is the underlying OS/filesystem error. The 'default' workspace and empty names are rejected earlier, so this is purely a filesystem failure.","triggerScenarios":"Calling terraform workspace delete <name> (or the backend DeleteWorkspace API) when the on-disk workspace directory under the state workspace dir cannot be removed — e.g. permission denied, path is a mount, file busy, or the directory was already removed/modified externally.","commonSituations":"Filesystem permission mismatch (state dir owned by root, terraform run as non-root); NFS/mount busy handles; antivirus or another process holding file handles on Windows; someone manually deleting the workspace dir out from under Terraform.","solutions":["Check the wrapped error for the OS cause (permission denied, busy, etc.) and fix ownership/permissions on the state directory.","Close other processes holding handles to the workspace files, then retry the delete.","If the directory is already gone, verify with terraform workspace list; manually clean the entry if state is inconsistent."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"diags := b.DeleteWorkspace(name, force)\nif diags.HasErrors() {\n    // inspect underlying cause; os.RemoveAll errors are in the diagnostics\n    return diags.Err()\n}","preventionTips":["Run terraform as a user that owns the state directory tree.","Avoid manually editing/deleting workspace directories under Terraform's state path.","On Windows/shared filesystems, ensure no process holds open handles before deleting workspaces."],"tags":["filesystem","backend","workspace","permissions","terraform"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T20:17:04.800Z"}