hcengineering/platform · error

Space #${parent.space} not found

Error message

Space #${parent.space} not found

What it means

createTrainingRequest resolves the parent space via lookup and throws when the space document cannot be found. The space is required to read its type and derive role assignments. Indicates the parent.space reference is dangling or the query misses the space.

Source

Thrown at plugins/training-resources/src/utils/createTrainingRequest.ts:42

  const { roles, ...attachedData } = data
  if (roles.length > 0) {
    const traineesMap = new Map<Ref<Employee>, boolean>(attachedData.trainees.map((employeeRef) => [employeeRef, true]))

    const space = await client.findOne(
      core.class.TypedSpace,
      {
        _id: parent.space
      },
      {
        lookup: {
          type: core.class.SpaceType
        }
      }
    )

    if (space === undefined) {
      throw new Error(`Space #${parent.space} not found`)
    }

    const spaceType = space.$lookup?.type

    if (spaceType === undefined) {
      throw new Error(`Space type #${space.type} not found`)
    }

    const mixin = client.getHierarchy().as(space, spaceType.targetClass) as unknown as RolesAssignment
    const personRefByAccountUuid = get(employeeRefByAccountUuidStore)
    const employeeRefs = new Set(
      roles
        .map((roleId) => mixin[roleId] ?? [])
        .flat()
        .map((acc) => personRefByAccountUuid.get(acc))
        .filter(notEmpty)
    )

View on GitHub (pinned to 63e28dc964)

Solutions

  1. Verify the referenced space exists and is queryable in the current workspace.
  2. Repair or reassign parent.space references pointing to deleted spaces.
  3. Check query filters (space, class SpaceType lookup) for over-restrictive conditions.
  4. Re-create the space if it was deleted intentionally and migrate requests to it.

Example fix

// before
await createTrainingRequest(parent, ...)
// after
const space = await client.findOne(core.class.Space, { _id: parent.space })
if (space === undefined) throw new Error('Select a valid space before creating a request')
await createTrainingRequest(parent, ...)
Defensive patterns

Strategy: validation

Validate before calling

const space = await client.findOne(core.class.Space, { _id: parent.space })
if (space === undefined) throw new Error('Pick a valid space first')

Type guard

function spaceExists(s: Space | undefined): s is Space { return s !== undefined }

Try / catch

try { return await createTrainingRequest(parent, roles) } catch (e) { if (e.message.includes('Space #')) promptSpaceReselect(); else throw e }

Prevention

When it happens

Trigger: Creating a training request where parent.space points to a deleted/nonexistent space, or the space lives in a space the client query cannot see.

Common situations: Spaces removed while requests were pending; cross-project references; wrong workspace; archived spaces filtered out of queries.

Related errors


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