{"record":{"id":"2e7e683805e7eca3","repo":"hcengineering/platform","slug":"workspaceuuid-is-required","errorCode":null,"errorMessage":"workspaceUuid is required","messagePattern":"workspaceUuid is required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/account/src/collections/mongo.ts","lineNumber":344,"sourceCode":"\n  async exists (query: Query<WorkspaceStatus>): Promise<boolean> {\n    return await this.wsCollection.exists(this.toWsQuery(query))\n  }\n\n  async find (query: Query<WorkspaceStatus>, sort?: Sort<WorkspaceStatus>, limit?: number): Promise<WorkspaceStatus[]> {\n    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","sourceCodeStart":326,"sourceCodeEnd":362,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/server/account/src/collections/mongo.ts#L326-L362","documentation":"WorkspaceStatusMongoDbCollection.insertOne stores status data embedded inside the workspace document, so it must know which workspace to update. If `workspaceUuid` is undefined in the input it cannot build the `{ uuid: ... }` lookup/update, so it throws before touching the database. This is a deliberate guard against an orphaned or unaddressable status write.","triggerScenarios":"Calling workspaceStatus.insertOne with an object lacking `workspaceUuid` — e.g. { active: true, name: 'ws' } — or passing `{ workspaceUuid: undefined }` after destructuring from a failed lookup. Any caller forwarding a Partial<WorkspaceStatus> built without first obtaining a workspace uuid.","commonSituations":"A workspace-create flow reading the generated uuid from a variable that is undefined because workspace creation failed or the wrong property was read; copying status objects from query results where `workspaceUuid` was mapped out; test fixtures seeding status without the uuid field.","solutions":["Always include a valid `workspaceUuid` in the object passed to insertOne.","Create/obtain the workspace first and use its returned uuid for the status insert.","Verify variable naming at the call site — a typo like `workspaceId` instead of `workspaceUuid` silently yields undefined.","Guard with an early check in the caller and return a clear client-facing validation error."],"exampleFix":"// before\nawait workspaceStatus.insertOne({ active: true })\n// after\nawait workspaceStatus.insertOne({ workspaceUuid: wsUuid, active: true })","handlingStrategy":"validation","validationCode":"function canInsertWorkspaceStatus(data) {\n  return data != null && typeof data.workspaceUuid === 'string' && data.workspaceUuid.length > 0\n}","typeGuard":"function hasWorkspaceUuid(d: Partial<WorkspaceStatus> | null | undefined): d is { workspaceUuid: WorkspaceUuid } & Partial<WorkspaceStatus> {\n  return d !== null && d !== undefined && (d as any).workspaceUuid !== undefined\n}","tryCatchPattern":"try {\n  await workspaceStatus.insertOne(data)\n} catch (err) {\n  if (err instanceof Error && err.message === 'workspaceUuid is required') {\n    throw new BadRequestError('workspaceUuid is required to set workspace status')\n  }\n  throw err\n}","preventionTips":["Always source workspaceUuid from the workspace creation return value, not from a manually built object.","Check for typos: the field must be exactly `workspaceUuid`, not `workspaceId` or `uuid`.","Assert the uuid is present in tests that seed workspace status fixtures.","Validate input with a schema (zod/joi) that marks workspaceUuid required."],"tags":["validation","mongodb","missing-required-field"],"backgroundTag":"missing-required-field","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}