{"record":{"id":"11dd0e9e2a4dea50","repo":"hcengineering/platform","slug":"space-parent-space-not-found","errorCode":null,"errorMessage":"Space #${parent.space} not found","messagePattern":"Space #(.+?) not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugins/training-resources/src/utils/createTrainingRequest.ts","lineNumber":42,"sourceCode":"\n  const { roles, ...attachedData } = data\n  if (roles.length > 0) {\n    const traineesMap = new Map<Ref<Employee>, boolean>(attachedData.trainees.map((employeeRef) => [employeeRef, true]))\n\n    const space = await client.findOne(\n      core.class.TypedSpace,\n      {\n        _id: parent.space\n      },\n      {\n        lookup: {\n          type: core.class.SpaceType\n        }\n      }\n    )\n\n    if (space === undefined) {\n      throw new Error(`Space #${parent.space} not found`)\n    }\n\n    const spaceType = space.$lookup?.type\n\n    if (spaceType === undefined) {\n      throw new Error(`Space type #${space.type} not found`)\n    }\n\n    const mixin = client.getHierarchy().as(space, spaceType.targetClass) as unknown as RolesAssignment\n    const personRefByAccountUuid = get(employeeRefByAccountUuidStore)\n    const employeeRefs = new Set(\n      roles\n        .map((roleId) => mixin[roleId] ?? [])\n        .flat()\n        .map((acc) => personRefByAccountUuid.get(acc))\n        .filter(notEmpty)\n    )\n","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/plugins/training-resources/src/utils/createTrainingRequest.ts#L24-L60","documentation":"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.","triggerScenarios":"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.","commonSituations":"Spaces removed while requests were pending; cross-project references; wrong workspace; archived spaces filtered out of queries.","solutions":["Verify the referenced space exists and is queryable in the current workspace.","Repair or reassign parent.space references pointing to deleted spaces.","Check query filters (space, class SpaceType lookup) for over-restrictive conditions.","Re-create the space if it was deleted intentionally and migrate requests to it."],"exampleFix":"// before\nawait createTrainingRequest(parent, ...)\n// after\nconst space = await client.findOne(core.class.Space, { _id: parent.space })\nif (space === undefined) throw new Error('Select a valid space before creating a request')\nawait createTrainingRequest(parent, ...)","handlingStrategy":"validation","validationCode":"const space = await client.findOne(core.class.Space, { _id: parent.space })\nif (space === undefined) throw new Error('Pick a valid space first')","typeGuard":"function spaceExists(s: Space | undefined): s is Space { return s !== undefined }","tryCatchPattern":"try { return await createTrainingRequest(parent, roles) } catch (e) { if (e.message.includes('Space #')) promptSpaceReselect(); else throw e }","preventionTips":["Validate parent.space with findOne before submitting","Prevent hard-deleting spaces that have pending requests","Restrict space pickers to existing, visible spaces"],"tags":["lookup","missing-object","space"],"backgroundTag":"referenced-object-not-found","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}