{"record":{"id":"0f1d16534f832890","repo":"hcengineering/platform","slug":"workspace-with-uuid-data-workspaceuuid-not-foun","errorCode":null,"errorMessage":"Workspace with uuid ${data.workspaceUuid} not found","messagePattern":"Workspace with uuid (.+?) not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/account/src/collections/mongo.ts","lineNumber":350,"sourceCode":"    return (await this.wsCollection.find(this.toWsQuery(query), this.toWsSort(sort), limit)).map((ws) => ({\n      ...ws.status,\n      workspaceUuid: ws.uuid\n    }))\n  }\n\n  async findOne (query: Query<WorkspaceStatus>): Promise<WorkspaceStatus | null> {\n    return (await this.wsCollection.findOne(this.toWsQuery(query)))?.status ?? null\n  }\n\n  async insertOne (data: Partial<WorkspaceStatus>): Promise<any> {\n    if (data.workspaceUuid === undefined) {\n      throw new Error('workspaceUuid is required')\n    }\n\n    const wsData = await this.wsCollection.findOne({ uuid: data.workspaceUuid })\n\n    if (wsData === null) {\n      throw new Error(`Workspace with uuid ${data.workspaceUuid} not found`)\n    }\n\n    const statusData: any = {}\n\n    for (const key of Object.keys(data)) {\n      if (key !== 'workspaceUuid') {\n        statusData[`status.${key}`] = (data as any)[key]\n      }\n    }\n\n    await this.wsCollection.update({ uuid: data.workspaceUuid }, statusData)\n\n    return data.workspaceUuid\n  }\n\n  async insertMany (data: Partial<WorkspaceStatus>[]): Promise<any> {\n    throw new Error('Not implemented')\n  }","sourceCodeStart":332,"sourceCodeEnd":368,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/server/account/src/collections/mongo.ts#L332-L368","documentation":"After validating that workspaceUuid is present, insertOne looks up the workspace document by uuid; if none exists it throws with the offending uuid interpolated into the message. Status data is stored on the workspace document itself, so a status insert for a nonexistent workspace would silently do nothing — the collection fails loudly instead. The runtime message contains the specific uuid.","triggerScenarios":"Calling workspaceStatus.insertOne({ workspaceUuid: '<uuid>', ... }) where no workspace with that uuid exists in wsCollection — workspace deleted earlier, uuid from another DB/environment, or a malformed/fabricated uuid. Also occurs when createWorkspace was rolled back or failed upstream while status creation still proceeded.","commonSituations":"Test fixtures referencing hardcoded uuids that were never seeded; staging code pointing at a production workspace uuid (or vice versa); a race where the workspace was deleted between obtaining the uuid and inserting status; migration scripts importing workspaces in the wrong order.","solutions":["Verify the workspace exists before inserting status: await workspace.findOne({ uuid }) or reuse the return value of workspace creation.","Fix the source of the bad uuid (wrong env, deleted workspace, wrong variable) — the message names the exact uuid to search for.","Order operations so the workspace document is created and committed before any status insert.","If workspace creation is async/eventual, confirm existence then retry the status insert rather than assuming the uuid is valid."],"exampleFix":"// before\nawait workspaceStatus.insertOne({ workspaceUuid: someUuid, active: true })\n// after\nconst ws = await workspace.findOne({ uuid: someUuid })\nif (ws === null) {\n  throw new Error(`Cannot set status: workspace ${someUuid} does not exist`)\n}\nawait workspaceStatus.insertOne({ workspaceUuid: someUuid, active: true })","handlingStrategy":"validation","validationCode":"async function assertWorkspaceExists(workspace, uuid) {\n  if (uuid == null) throw new Error('workspaceUuid is required')\n  const ws = await workspace.findOne({ uuid })\n  if (ws === null) throw new Error(`workspace ${uuid} does not exist`)\n  return true\n}","typeGuard":"function isKnownWorkspace(ws: WorkspaceInfoWithStatus | null, uuid: WorkspaceUuid): ws is WorkspaceInfoWithStatus {\n  return ws !== null && ws.uuid === uuid\n}","tryCatchPattern":"try {\n  await workspaceStatus.insertOne({ workspaceUuid, ...status })\n} catch (err) {\n  if (err instanceof Error && err.message.startsWith('Workspace with uuid ')) {\n    throw new NotFoundError(err.message)\n  }\n  throw err\n}","preventionTips":["Create the workspace document before inserting any status for it.","Reuse the uuid returned by workspace creation rather than passing ids from external input.","Do not hardcode workspace uuids in tests/fixtures — seed them and read the generated ids.","Handle deletion races: if a workspace may be removed concurrently, catch the not-found error and retry or abort gracefully."],"tags":["mongodb","not-found","referential-integrity"],"backgroundTag":"document-not-found","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}