{"record":{"id":"ad671c0cbe3ee739","repo":"hcengineering/platform","slug":"platform-status-workspacenotfound","errorCode":"platform.status.WorkspaceNotFound","errorMessage":"WorkspaceNotFound","messagePattern":"WorkspaceNotFound","errorType":"exception","errorClass":"PlatformError","httpStatus":null,"severity":"error","filePath":"server/account/src/operations.ts","lineNumber":775,"sourceCode":"    expiration?: number\n    personalized?: boolean\n  }\n): Promise<string> {\n  const { role, firstName, lastName, navigateUrl, spaces, notBefore, expiration, personalized = true } = params\n  const { account, workspace: workspaceUuid, extra } = decodeTokenVerbose(ctx, token)\n\n  const currentAccount = await db.account.findOne({ uuid: account })\n  if (currentAccount == null) {\n    throw new PlatformError(new Status(Severity.ERROR, platform.status.AccountNotFound, { account }))\n  }\n\n  if (workspaceUuid == null) {\n    throw new PlatformError(new Status(Severity.ERROR, platform.status.BadRequest, {}))\n  }\n\n  const workspace = await db.workspace.findOne({ uuid: workspaceUuid })\n  if (workspace == null) {\n    throw new PlatformError(new Status(Severity.ERROR, platform.status.WorkspaceNotFound, { workspaceUuid }))\n  }\n\n  let extraObj: Record<string, string> | undefined\n\n  if (params.extra != null) {\n    try {\n      extraObj = JSON.parse(params.extra)\n    } catch (e) {\n      ctx.error(\"Invalid extra parameter, couldn't parse JSON\", { extra: params.extra })\n      throw new PlatformError(new Status(Severity.ERROR, platform.status.BadRequest, {}))\n    }\n  }\n\n  const RECENT_PAST_MS = 1577836800000 // January 1, 2020 in milliseconds\n\n  if (notBefore !== undefined && notBefore > RECENT_PAST_MS) {\n    ctx.error('Not before appears to be in milliseconds instead of seconds', { nbf: notBefore })\n    throw new PlatformError(new Status(Severity.ERROR, platform.status.BadRequest, {}))","sourceCodeStart":757,"sourceCodeEnd":793,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/server/account/src/operations.ts#L757-L793","documentation":"createAccessLink looks up the workspace UUID from the token via db.workspace.findOne. If the workspace row does not exist, it throws WorkspaceNotFound. The token is structurally valid but references a deleted or foreign workspace.","triggerScenarios":"Calling createAccessLink with a token whose workspace UUID was deleted, or that belongs to a different database/environment than the one being queried.","commonSituations":"Workspace removed (or archived) while users still hold tokens for it; restoring one environment's DB while using another's tokens; hard-coded workspace UUIDs in scripts pointing at the wrong instance.","solutions":["Re-authenticate to get a token bound to an existing workspace.","Verify the workspace exists: db.workspace.findOne({ uuid: <workspace from token> }).","Check you are connecting to the same environment the token was issued for.","If the workspace was deleted intentionally, direct users to a remaining workspace before generating access links."],"exampleFix":"// before: token referencing deleted workspace\nconst link = await createAccessLink(staleToken, params)\n// after: pick a workspace the account still belongs to\nconst token = await loginForWorkspace(email, password, existingWorkspaceUuid)\nconst link = await createAccessLink(token, params)","handlingStrategy":"try-catch","validationCode":"const wsUuid = decodeJwt(token)?.workspace\nif (wsUuid != null && !(await workspaceExists(wsUuid))) {\n  throw new Error('Workspace from token no longer exists; re-authenticate')\n}","typeGuard":"function isWorkspaceRef(w: unknown): w is { uuid: string } {\n  return typeof w === 'object' && w !== null && typeof (w as any).uuid === 'string'\n}","tryCatchPattern":"try {\n  const link = await createAccessLink(token, params)\n} catch (err) {\n  if (isPlatformError(err, platform.status.WorkspaceNotFound)) {\n    const token = await loginForWorkspace(email, password, pickExistingWorkspace())\n    // retry once with fresh token\n  } else throw err\n}","preventionTips":["Refresh tokens whenever the active workspace changes or is deleted.","Check workspace existence before generating links in automation.","Avoid hard-coding workspace UUIDs; resolve them at runtime."],"tags":["workspace","not-found","token","auth"],"backgroundTag":"workspace-not-found","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}