hcengineering/platform · error

Workspace with uuid ${data.workspaceUuid} not found

Error message

Workspace with uuid ${data.workspaceUuid} not found

What it means

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.

Source

Thrown at server/account/src/collections/mongo.ts:350

    return (await this.wsCollection.find(this.toWsQuery(query), this.toWsSort(sort), limit)).map((ws) => ({
      ...ws.status,
      workspaceUuid: ws.uuid
    }))
  }

  async findOne (query: Query<WorkspaceStatus>): Promise<WorkspaceStatus | null> {
    return (await this.wsCollection.findOne(this.toWsQuery(query)))?.status ?? null
  }

  async insertOne (data: Partial<WorkspaceStatus>): Promise<any> {
    if (data.workspaceUuid === undefined) {
      throw new Error('workspaceUuid is required')
    }

    const wsData = await this.wsCollection.findOne({ uuid: data.workspaceUuid })

    if (wsData === null) {
      throw new Error(`Workspace with uuid ${data.workspaceUuid} not found`)
    }

    const statusData: any = {}

    for (const key of Object.keys(data)) {
      if (key !== 'workspaceUuid') {
        statusData[`status.${key}`] = (data as any)[key]
      }
    }

    await this.wsCollection.update({ uuid: data.workspaceUuid }, statusData)

    return data.workspaceUuid
  }

  async insertMany (data: Partial<WorkspaceStatus>[]): Promise<any> {
    throw new Error('Not implemented')
  }

View on GitHub (pinned to 63e28dc964)

Solutions

  1. Verify the workspace exists before inserting status: await workspace.findOne({ uuid }) or reuse the return value of workspace creation.
  2. Fix the source of the bad uuid (wrong env, deleted workspace, wrong variable) — the message names the exact uuid to search for.
  3. Order operations so the workspace document is created and committed before any status insert.
  4. If workspace creation is async/eventual, confirm existence then retry the status insert rather than assuming the uuid is valid.

Example fix

// before
await workspaceStatus.insertOne({ workspaceUuid: someUuid, active: true })
// after
const ws = await workspace.findOne({ uuid: someUuid })
if (ws === null) {
  throw new Error(`Cannot set status: workspace ${someUuid} does not exist`)
}
await workspaceStatus.insertOne({ workspaceUuid: someUuid, active: true })
Defensive patterns

Strategy: validation

Validate before calling

async function assertWorkspaceExists(workspace, uuid) {
  if (uuid == null) throw new Error('workspaceUuid is required')
  const ws = await workspace.findOne({ uuid })
  if (ws === null) throw new Error(`workspace ${uuid} does not exist`)
  return true
}

Type guard

function isKnownWorkspace(ws: WorkspaceInfoWithStatus | null, uuid: WorkspaceUuid): ws is WorkspaceInfoWithStatus {
  return ws !== null && ws.uuid === uuid
}

Try / catch

try {
  await workspaceStatus.insertOne({ workspaceUuid, ...status })
} catch (err) {
  if (err instanceof Error && err.message.startsWith('Workspace with uuid ')) {
    throw new NotFoundError(err.message)
  }
  throw err
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of hcengineering/platform@63e28dc964 (2026-08-29). Data as JSON: /api/errors/0f1d16534f832890. Report an issue: GitHub.