{"record":{"id":"33ed40b69c8e15b3","repo":"windmill-labs/windmill","slug":"workspace-not-found","errorCode":null,"errorMessage":"Workspace not found","messagePattern":"Workspace not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"frontend/src/lib/components/waitJob.ts","lineNumber":16,"sourceCode":"import { JobService } from '$lib/gen'\nimport { workspaceStore } from '$lib/stores'\nimport { get } from 'svelte/store'\n\nconst ITERATIONS_BEFORE_SLOW_REFRESH = 10\nconst ITERATIONS_BEFORE_SUPER_SLOW_REFRESH = 100\n\nexport async function waitJob(id: string, forceWorkspace?: string) {\n\tconst workspace = forceWorkspace || get(workspaceStore)\n\n\tif (!id) {\n\t\treturn\n\t}\n\n\tif (!workspace) {\n\t\tthrow new Error('Workspace not found')\n\t}\n\n\tlet syncIteration: number = 0\n\tlet errorIteration: number = 0\n\tlet job: any\n\n\treturn new Promise((resolve, reject) => {\n\t\tasync function checkJob() {\n\t\t\ttry {\n\t\t\t\tconst maybeJob = await JobService.getCompletedJobResultMaybe({\n\t\t\t\t\tworkspace: workspace!,\n\t\t\t\t\tid,\n\t\t\t\t\tgetStarted: false\n\t\t\t\t})\n\n\t\t\t\tif (maybeJob.completed) {\n\t\t\t\t\tjob = { ...maybeJob, id }\n","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/windmill-labs/windmill/blob/e474e8803ce2ff5c2df09a58dab51d45f5c922ca/frontend/src/lib/components/waitJob.ts#L1-L34","documentation":"waitJob polls a job's result through the workspace API, so it needs to know which workspace to query. It reads forceWorkspace or the global workspaceStore; if neither yields a workspace (empty string/undefined) it throws 'Workspace not found' before starting to poll.","triggerScenarios":"Calling waitJob(id) with no forceWorkspace argument while workspaceStore is unset/empty — e.g. the store was not initialized yet, the user is not logged into any workspace, or the caller runs outside a workspace-scoped page.","commonSituations":"Calling waitJob during app startup before the workspace store is populated; passing an empty-string workspace variable; invoking job-waiting logic from a context that has no active workspace (logged out, shared run page without workspace context).","solutions":["Pass the workspace explicitly: waitJob(id, 'my-workspace') instead of relying on workspaceStore","Ensure the user is logged in and workspaceStore is initialized before calling waitJob","Guard the call site: skip waitJob when no workspace is available, mirroring the existing `if (!id) return` early return"],"exampleFix":"// before\nawait waitJob(jobId)\n// after\nconst workspace = get(workspaceStore)\nif (!workspace) throw new Error('Cannot wait for job: no active workspace')\nawait waitJob(jobId, workspace)","handlingStrategy":"validation","validationCode":"const workspace = forceWorkspace || get(workspaceStore)\nif (!workspace) throw new Error('waitJob requires an active workspace')","typeGuard":"function hasWorkspace(w: string | undefined | null): w is string { return typeof w === 'string' && w.length > 0 }","tryCatchPattern":"try {\n  const result = await waitJob(id)\n} catch (e) {\n  if ((e as Error).message === 'Workspace not found') {\n    // prompt user to select/login to a workspace before retrying\n  }\n}","preventionTips":["Always pass forceWorkspace when waiting on jobs from outside a workspace-scoped page","Initialize/login before any job polling logic runs","Treat an empty workspaceStore as a hard precondition failure at call sites"],"tags":["workspace","state","frontend"],"backgroundTag":"missing-workspace-context","analyzedSha":"e474e8803ce2ff5c2df09a58dab51d45f5c922ca","analyzedAt":"2026-09-03T12:38:19.024Z","contentChangedAt":"2026-09-03T12:38:19.024Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}