{"record":{"id":"7928f2ee29d9601b","repo":"wavetermdev/waveterm","slug":"error-updating-window-w","errorCode":null,"errorMessage":"error updating window: %w","messagePattern":"error updating window: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/wcore/window.go","lineNumber":52,"sourceCode":"\t}\n\n\tallWindows, err := wstore.DBGetAllObjsByType[*waveobj.Window](ctx, waveobj.OType_Window)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error getting all windows: %w\", err)\n\t}\n\n\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}","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/pkg/wcore/window.go#L34-L70","documentation":"SwitchWorkspace failed to persist the updated Window record (with its new WorkspaceId) via wstore.DBUpdate after re-pointing the window at the target workspace. This error wraps the underlying wstore/db failure, so the root cause is in the wrapped message. The window's in-memory WorkspaceId was already mutated, but the change was never committed.","triggerScenarios":"Calling wcore.SwitchWorkspace(ctx, windowId, workspaceId) when the target workspace exists and is not already bound to another window, and the subsequent wstore.DBUpdate(ctx, window) fails (DB closed, corrupted, OID not found, or write-level error).","commonSituations":"Corrupted or locked waveterm DB file; stale window OID after another process deleted the window; disk-full or permission errors on the user's state directory; racing two SwitchWorkspace calls from different clients for the same window.","solutions":["Inspect the wrapped %w error to find the root wstore/db cause (e.g. 'not found' vs I/O error)","Verify the windowId still exists with wcore.GetWindow before switching","Check the DB file (~/.waveterm) for corruption or permission problems","Retry the switch after confirming no concurrent modification of the same window"],"exampleFix":"// before\nerr = wstore.DBUpdate(ctx, window)\nif err != nil {\n\treturn nil, fmt.Errorf(\"error updating window: %w\", err)\n}\n// after\nwindow, err = GetWindow(ctx, windowId) // re-read to confirm it still exists\nif err != nil {\n\treturn nil, fmt.Errorf(\"window vanished before update: %w\", err)\n}\nwindow.WorkspaceId = workspaceId\nif err := wstore.DBUpdate(ctx, window); err != nil {\n\treturn nil, fmt.Errorf(\"error updating window: %w\", err)\n}","handlingStrategy":"try-catch","validationCode":"win, err := wcore.GetWindow(ctx, windowId)\nif err != nil {\n\treturn fmt.Errorf(\"window %s unavailable before switch: %w\", windowId, err)\n}\nif _, err := wcore.GetWorkspace(ctx, workspaceId); err != nil {\n\treturn fmt.Errorf(\"target workspace unavailable: %w\", err)\n}","typeGuard":"func windowValid(w *waveobj.Window) bool { return w != nil && w.OID != \"\" && w.WorkspaceId != \"\" }","tryCatchPattern":"newWs, err := wcore.SwitchWorkspace(ctx, windowId, workspaceId)\nif err != nil {\n\tif strings.Contains(err.Error(), \"error updating window\") {\n\t\tlog.Printf(\"DB update failed during switch, retry after checking window state: %v\", err)\n\t\t// re-fetch window and retry or abort\n\t}\n\treturn err\n}","preventionTips":["Always verify windowId and workspaceId exist before switching","Avoid concurrent SwitchWorkspace calls for the same window","Monitor disk space and DB file health on the waveterm state directory"],"tags":["database","wave-terminal","workspace","persistence"],"backgroundTag":"database-update-failed","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}