{"record":{"id":"71334facd52514dd","repo":"wavetermdev/waveterm","slug":"error-deleting-workspace-w-71334f","errorCode":null,"errorMessage":"error deleting workspace: %w","messagePattern":"error deleting workspace: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/wcore/window.go","lineNumber":59,"sourceCode":"\tfor _, w := range allWindows {\n\t\tif w.WorkspaceId == workspaceId {\n\t\t\tlog.Printf(\"workspace %s already has a window %s, focusing that window\\n\", workspaceId, w.OID)\n\t\t\tclient := wshclient.GetBareRpcClient()\n\t\t\terr = wshclient.FocusWindowCommand(client, w.OID, &wshrpc.RpcOpts{Route: wshutil.ElectronRoute})\n\t\t\treturn nil, err\n\t\t}\n\t}\n\twindow.WorkspaceId = workspaceId\n\terr = wstore.DBUpdate(ctx, window)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error updating window: %w\", err)\n\t}\n\n\tdeleted, _, err := DeleteWorkspace(ctx, curWsId, false)\n\tif err != nil && deleted {\n\t\tprint(err.Error()) // @jalileh isolated the error for now, curwId/workspace was deleted when this occurs.\n\t} else if err != nil {\n\t\treturn nil, fmt.Errorf(\"error deleting workspace: %w\", err)\n\t}\n\n\tif !deleted {\n\t\tlog.Printf(\"current workspace %s was not deleted\\n\", curWsId)\n\t} else {\n\t\tlog.Printf(\"deleted current workspace %s\\n\", curWsId)\n\t}\n\n\tlog.Printf(\"switching window %s to workspace %s\\n\", windowId, workspaceId)\n\treturn ws, nil\n}\n\nfunc GetWindow(ctx context.Context, windowId string) (*waveobj.Window, error) {\n\twindow, err := wstore.DBMustGet[*waveobj.Window](ctx, windowId)\n\tif err != nil {\n\t\tlog.Printf(\"error getting window %q: %v\\n\", windowId, err)\n\t\treturn nil, err\n\t}","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/pkg/wcore/window.go#L41-L77","documentation":"After re-pointing the window to the new workspace, SwitchWorkspace calls DeleteWorkspace on the old workspace; if that delete fails AND the workspace was not actually deleted, this error wraps the underlying cause. Note: if the workspace was deleted despite the error, the error is only printed, not returned (known isolated quirk flagged in the source comment).","triggerScenarios":"wcore.SwitchWorkspace(ctx, windowId, workspaceId) where DeleteWorkspace(ctx, curWsId, false) returns err != nil and deleted == false — e.g. the old workspace still has tabs/windows blocking deletion and the delete operation itself errors.","commonSituations":"Old workspace contains dependent blocks/tabs that fail to clean up; concurrent clients mutating the same workspace; DB write error while removing workspace objects after a partial delete.","solutions":["Read the wrapped %w error to see why DeleteWorkspace failed","Check whether the old workspace still has tabs (DeleteWorkspace only deletes empty/unnamed workspaces per its contract)","Manually inspect the DB for orphaned workspace rows and clean up","Report/fix the known quirk where err+deleted==true is only printed and swallowed"],"exampleFix":"// before\ndeleted, _, err := DeleteWorkspace(ctx, curWsId, false)\nif err != nil && deleted {\n\tprint(err.Error())\n} else if err != nil {\n\treturn nil, fmt.Errorf(\"error deleting workspace: %w\", err)\n}\n// after\ndeleted, _, err := DeleteWorkspace(ctx, curWsId, false)\nif err != nil {\n\tlog.Printf(\"deleting old workspace %s (deleted=%v): %v\", curWsId, deleted, err)\n\tif !deleted {\n\t\treturn nil, fmt.Errorf(\"error deleting workspace: %w\", err)\n\t}\n}","handlingStrategy":"try-catch","validationCode":"ws, err := wcore.GetWorkspace(ctx, curWorkspaceId)\nif err == nil && ws != nil {\n\t// old workspace still present; safe to attempt switch and cleanup\n}","typeGuard":null,"tryCatchPattern":"ws, err := wcore.SwitchWorkspace(ctx, windowId, workspaceId)\nif err != nil {\n\tif strings.Contains(err.Error(), \"error deleting workspace\") {\n\t\tlog.Printf(\"switch likely succeeded but old workspace cleanup failed: %v\", err)\n\t\t// schedule cleanup, don't necessarily abort the switch\n\t\treturn nil\n\t}\n\treturn err\n}","preventionTips":["Understand DeleteWorkspace only removes empty/unnamed workspaces — name or empty the old workspace first if you need deterministic deletion","Check for orphaned workspaces after switches and clean them up","Don't treat this error as a failed switch; the window may already be on the new workspace"],"tags":["database","wave-terminal","workspace","cleanup"],"backgroundTag":"workspace-delete-failed","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}