{"record":{"id":"f89bc6542832513c","repo":"hcengineering/platform","slug":"process-error-relatedobjectnotfound","errorCode":"process.error.RelatedObjectNotFound","errorMessage":"Related object not f  ound: {attr}","messagePattern":"Related object not f  ound: (.+?)","errorType":"exception","errorClass":"ProcessError","httpStatus":null,"severity":"error","filePath":"server-plugins/process-resources/src/utils.ts","lineNumber":144,"sourceCode":"}\n\nasync function getNestedValue (control: ProcessControl, execution: Execution, context: SelectedNested): Promise<any> {\n  const card = control.cache.get(execution.card)\n  if (card === undefined) throw processError(process.error.ObjectNotFound, { _id: execution.card }, {}, true)\n  const _process = control.client.getModel().findObject(execution.process)\n  if (_process === undefined) throw processError(process.error.ObjectNotFound, { _id: execution.process })\n  const realPath = resolveAttributeId(_process, context.path)\n  const attr = control.client.getHierarchy().findAttribute(card._class, realPath)\n  if (attr === undefined) throw processError(process.error.AttributeNotExists, { key: realPath })\n  const nestedValue = getValue(control, execution, context.path, card)\n  if (nestedValue === undefined) throw processError(process.error.EmptyAttributeContextValue, {}, { attr: attr.label })\n  const parentType = attr.type._class === core.class.ArrOf ? (attr.type as ArrOf<Doc>).of : attr.type\n  const targetClass = parentType._class === core.class.RefTo ? (parentType as RefTo<Doc>).to : parentType._class\n  const refs = Array.isArray(nestedValue) ? nestedValue : [nestedValue]\n  const target = await control.client.findAll(targetClass, {\n    _id: { $in: refs }\n  })\n  if (target.length === 0) throw processError(process.error.RelatedObjectNotFound, {}, { attr: attr.label })\n  const realKey = resolveAttributeId(_process, context.key)\n  const nested = control.client.getHierarchy().findAttribute(targetClass, realKey)\n  if (context.sourceFunction !== undefined) {\n    const transform = control.client.getModel().findObject(context.sourceFunction.func)\n    if (transform === undefined) {\n      throw processError(process.error.MethodNotFound, { methodId: context.sourceFunction.func }, {}, true)\n    }\n    if (!control.client.getHierarchy().hasMixin(transform, serverProcess.mixin.FuncImpl)) {\n      throw processError(process.error.MethodNotFound, { methodId: context.sourceFunction.func }, {}, true)\n    }\n    const funcImpl = control.client.getHierarchy().as(transform, serverProcess.mixin.FuncImpl)\n    const f = await getResource(funcImpl.func)\n    const reduced = await f(target, {}, control, execution)\n    const val = Array.isArray(reduced)\n      ? reduced.map((v) => getValue(control, execution, context.key, v))\n      : getValue(control, execution, context.key, reduced)\n    if (val == null) {\n      throw processError(","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/server-plugins/process-resources/src/utils.ts#L126-L162","documentation":"Thrown by getNestedValue after findAll on the referenced target class returns no documents — the nested attribute's referenced objects cannot be found. Message carries the attribute label.","triggerScenarios":"getNestedValue resolving a RefTo/ArrOf reference attribute whose _id(s) are passed to control.client.findAll, but zero matching documents are returned: references were deleted, ids are stale, or permissions/space filters exclude them.","commonSituations":"Referenced objects deleted (or moved to another space) after being linked; cross-workspace imports with dangling references; security/visibility filters hiding the referenced docs from the current client.","solutions":["Check the referenced _ids exist and are visible to the current client (query findAll manually with the same ids).","Repair or clear dangling references on the card; re-link to existing objects.","Check space/permission filters in findAll that may hide valid targets.","Add referential integrity checks before deleting objects that are referenced by process executions."],"exampleFix":"// before\nconst nested = await getNestedValue(control, execution, ctx)\n// after: verify references resolve\nconst refs = Array.isArray(card[ctx.path]) ? card[ctx.path] : [card[ctx.path]]\nconst found = await control.client.findAll(targetClass, { _id: { $in: refs } })\nif (found.length === 0) throw new Error('Referenced objects missing for ' + ctx.path)\nconst nested = await getNestedValue(control, execution, ctx)","handlingStrategy":"validation","validationCode":"const refs = Array.isArray(card[context.path]) ? card[context.path] : [card[context.path]]\nconst found = await control.client.findAll(targetClass, { _id: { $in: refs } })\nif (found.length === 0) throw new Error('Referenced objects missing')","typeGuard":"async function refsResolve(client: Client, targetClass: Ref<Class<Doc>>, refs: Ref<Doc>[]): Promise<boolean> {\n  return (await client.findAll(targetClass, { _id: { $in: refs }, limit: 1 })).length > 0\n}","tryCatchPattern":"try {\n  const value = await getNestedValue(control, execution, ctx)\n} catch (err) {\n  if ((err as Error).message.startsWith('Related object not found')) {\n    // repair dangling references or re-link\n  } else throw err\n}","preventionTips":["Enforce referential integrity before deleting referenced objects","Check space/permission visibility of referenced docs","Clean dangling references after imports/restores","Periodically audit reference attributes for dead links"],"tags":["process","broken-reference","dangling-ref"],"backgroundTag":"referenced-object-not-found","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}