{"record":{"id":"e27eecfe88d939ab","repo":"wavetermdev/waveterm","slug":"error-getting-workspace-w","errorCode":null,"errorMessage":"error getting workspace: %w","messagePattern":"error getting workspace: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/service/workspaceservice/workspaceservice.go","lineNumber":81,"sourceCode":"\t\t}()\n\t\twps.Broker.SendUpdateEvents(updates)\n\t}()\n\treturn updates, nil\n}\n\nfunc (svc *WorkspaceService) GetWorkspace_Meta() tsgenmeta.MethodMeta {\n\treturn tsgenmeta.MethodMeta{\n\t\tArgNames:   []string{\"workspaceId\"},\n\t\tReturnDesc: \"workspace\",\n\t}\n}\n\nfunc (svc *WorkspaceService) GetWorkspace(workspaceId string) (*waveobj.Workspace, error) {\n\tctx, cancelFn := context.WithTimeout(context.Background(), DefaultTimeout)\n\tdefer cancelFn()\n\tws, err := wstore.DBGet[*waveobj.Workspace](ctx, workspaceId)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error getting workspace: %w\", err)\n\t}\n\treturn ws, nil\n}\n\nfunc (svc *WorkspaceService) DeleteWorkspace_Meta() tsgenmeta.MethodMeta {\n\treturn tsgenmeta.MethodMeta{\n\t\tArgNames: []string{\"workspaceId\"},\n\t}\n}\n\nfunc (svc *WorkspaceService) DeleteWorkspace(workspaceId string) (waveobj.UpdatesRtnType, string, error) {\n\tctx, cancelFn := context.WithTimeout(context.Background(), DefaultTimeout)\n\tdefer cancelFn()\n\tctx = waveobj.ContextWithUpdates(ctx)\n\tdeleted, claimableWorkspace, err := wcore.DeleteWorkspace(ctx, workspaceId, true)\n\tif claimableWorkspace != \"\" {\n\t\treturn nil, claimableWorkspace, nil\n\t}","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/pkg/service/workspaceservice/workspaceservice.go#L63-L99","documentation":"WorkspaceService.GetWorkspace reads a Workspace from wstore by OID with a DefaultTimeout context and wraps DBGet failures with this error. It most commonly means no workspace exists with the given workspaceId, or the DB read timed out/failed.","triggerScenarios":"GetWorkspace called with a deleted workspace's OID, a malformed/empty id, an id pointing to a non-workspace object, or when the wstore read exceeds DefaultTimeout or errors.","commonSituations":"Frontend restoring state referencing workspaces removed since last session; race after DeleteWorkspace; hardcoded OIDs in tests/scripts; slow disk or large DB causing the timeout to fire.","solutions":["Verify the workspaceId against the current workspace list before calling; refresh if it is stale","Treat not-found as terminal — do not retry with the same id; fall back to fetching all workspaces","Unwrap the %w error: if it is a timeout, check DB health and consider increasing retry backoff (timeout itself is fixed by DefaultTimeout)","If ids come from persisted config/state, validate and prune stale references at load time"],"exampleFix":"// before\nws, err := WorkspaceService.GetWorkspace(oldConfigWsId) // stale id\n// after\nworkspaces := GetAllWorkspaces()\nwsId := pickValidId(workspaces, oldConfigWsId)","handlingStrategy":"try-catch","validationCode":"const wss = await WorkspaceService.GetAllWorkspaces();\nif (!wss.some(w => w.OID === workspaceId)) throw new Error(`workspace ${workspaceId} not in current list`);","typeGuard":"function isWorkspaceWithId(w: waveobj.Workspace | undefined, id: string): w is waveobj.Workspace {\n  return w != null && w.OID === id;\n}","tryCatchPattern":"ws, err := WorkspaceService.GetWorkspace(workspaceId)\nif err != nil {\n    var nf *wstore.NotFoundError\n    if errors.As(err, &nf) { return fallbackToWorkspaceList() }\n    return fmt.Errorf(\"get workspace %s: %w\", workspaceId, err)\n}","preventionTips":["Prune stale workspace OIDs from persisted config/state at load time","Use GetAllWorkspaces as a fallback when a specific id is missing","Do not cache workspace objects across sessions; always re-resolve ids"],"tags":["workspace","database","not-found"],"backgroundTag":"waveobj-not-found","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}