{"record":{"id":"19438233f10a9d6f","repo":"wavetermdev/waveterm","slug":"error-getting-workspace-w-194382","errorCode":null,"errorMessage":"error getting workspace: %w","messagePattern":"error getting workspace: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/wcore/window.go","lineNumber":93,"sourceCode":"\t\tlog.Printf(\"error getting window %q: %v\\n\", windowId, err)\n\t\treturn nil, err\n\t}\n\treturn window, nil\n}\n\nfunc CreateWindow(ctx context.Context, winSize *waveobj.WinSize, workspaceId string) (*waveobj.Window, error) {\n\tlog.Printf(\"CreateWindow %v %v\\n\", winSize, workspaceId)\n\tvar ws *waveobj.Workspace\n\tif workspaceId == \"\" {\n\t\tws1, err := CreateWorkspace(ctx, \"\", \"\", \"\", false, false)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"error creating workspace: %w\", err)\n\t\t}\n\t\tws = ws1\n\t} else {\n\t\tws1, err := GetWorkspace(ctx, workspaceId)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"error getting workspace: %w\", err)\n\t\t}\n\t\tws = ws1\n\t}\n\twindowId := uuid.NewString()\n\tif winSize == nil {\n\t\twinSize = &waveobj.WinSize{\n\t\t\tWidth:  0,\n\t\t\tHeight: 0,\n\t\t}\n\t}\n\twindow := &waveobj.Window{\n\t\tOID:         windowId,\n\t\tWorkspaceId: ws.OID,\n\t\tIsNew:       true,\n\t\tPos: waveobj.Point{\n\t\t\tX: 0,\n\t\t\tY: 0,\n\t\t},","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/pkg/wcore/window.go#L75-L111","documentation":"CreateWindow with a non-empty workspaceId looks up the target workspace via GetWorkspace; this error wraps the lookup failure. GetWorkspace uses DBMustGet, so a missing OID is itself an error here, not a nil result.","triggerScenarios":"wcore.CreateWindow(ctx, winSize, workspaceId) where workspaceId is non-empty and GetWorkspace fails — typically the workspace OID does not exist in wstore (deleted by another client) or the DB read fails.","commonSituations":"Caller passes a stale workspaceId saved from a previous session; workspace was deleted when its last window closed (CloseWindow auto-deletes empty workspaces); typo'd or malformed UUID; DB read error.","solutions":["Validate the workspaceId exists before calling CreateWindow (fetch workspace list first)","Pass \"\" for workspaceId to let CreateWindow make a fresh workspace instead","Check the wrapped %w error for 'not found' vs I/O failure","Refresh any cached workspace IDs after workspaces are deleted"],"exampleFix":"// before\nwin, err := wcore.CreateWindow(ctx, nil, staleWorkspaceId)\n// after\nwsList, err := wstore.DBGetAllObjsByType[*waveobj.Workspace](ctx, waveobj.OType_Workspace)\nif err != nil {\n\treturn err\n}\nvar wsId string\nfor _, ws := range wsList {\n\tif ws.OID == staleWorkspaceId {\n\t\twsId = staleWorkspaceId\n\t\tbreak\n\t}\n}\nwin, err := wcore.CreateWindow(ctx, nil, wsId) // \"\" if not found -> creates new workspace","handlingStrategy":"validation","validationCode":"func workspaceExists(ctx context.Context, wsId string) bool {\n\tif wsId == \"\" {\n\t\treturn true // CreateWindow will make a new one\n\t}\n\t_, err := wcore.GetWorkspace(ctx, wsId)\n\treturn err == nil\n}","typeGuard":"func hasWorkspaceId(workspaceId string) bool {\n\t_, err := uuid.Parse(workspaceId)\n\treturn err == nil\n}","tryCatchPattern":"win, err := wcore.CreateWindow(ctx, winSize, workspaceId)\nif err != nil && strings.Contains(err.Error(), \"error getting workspace\") {\n\tlog.Printf(\"workspace %s gone, falling back to new workspace\", workspaceId)\n\twin, err = wcore.CreateWindow(ctx, winSize, \"\")\n}","preventionTips":["Never cache workspaceIds across sessions without revalidating them","Remember CloseWindow auto-deletes empty workspaces — an old ID may be stale","Pass \"\" instead of a dubious ID to get a fresh workspace"],"tags":["wave-terminal","workspace","lookup","invalid-id"],"backgroundTag":"entity-not-found","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}