{"record":{"id":"df286cc795f53dd5","repo":"hcengineering/platform","slug":"process-error-objectnotfound","errorCode":"process.error.ObjectNotFound","errorMessage":"ObjectNotFound: ${execution.card}","messagePattern":"ObjectNotFound: (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server-plugins/process-resources/src/functions.ts","lineNumber":330,"sourceCode":"      if (max !== undefined && res > max) res = max\n      if (digits !== undefined) {\n        return Number(Number(res).toFixed(digits))\n      }\n      return res\n    }\n    default:\n      return value\n  }\n}\n\nexport async function UpdateCard (\n  params: MethodParams<Card>,\n  execution: Execution,\n  control: ProcessControl\n): Promise<ExecuteResult> {\n  if (Object.keys(params).length === 0) throw processError(process.error.RequiredParamsNotProvided, { params: 'ANY' })\n  const target = control.cache.get(execution.card)\n  if (target === undefined) throw processError(process.error.ObjectNotFound, { _id: execution.card })\n  const hierarchy = control.client.getHierarchy()\n  const _process = control.client.getModel().findObject(execution.process)\n  if (_process === undefined) throw processError(process.error.ObjectNotFound, { _id: execution.process })\n  const update: Record<string, any> = {}\n  const prevValue: Record<string, any> = {}\n  for (const key in params) {\n    const realKey = resolveAttributeId(_process, key)\n    const prevKey = checkMixinKey(realKey, _process.masterTag, hierarchy)\n    prevValue[realKey] = getObjectValue(prevKey, target)\n    const attr = hierarchy.findAttribute(_process.masterTag, realKey)\n    if (attr === undefined) {\n      update[realKey] = (params as any)[key]\n    } else {\n      update[realKey] = respectAttributeType(attr.type, (params as any)[key])\n    }\n  }\n\n  const res: Tx[] = []","sourceCodeStart":312,"sourceCodeEnd":348,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/server-plugins/process-resources/src/functions.ts#L312-L348","documentation":"UpdateCard looks up the card being executed (execution.card) in control.cache and throws ObjectNotFound when it is undefined — the object the process execution is attached to could not be resolved. This is thrown before any update transaction is built, so execution aborts.","triggerScenarios":"Running an UpdateCard process execution whose execution.card references a card that does not exist (deleted, wrong space, wrong id in the Execution object), or when the cache was not populated for that card.","commonSituations":"The card was deleted after the process/advisor started but the execution still fires; a copy/import created Execution objects pointing at stale ids; test fixtures using fabricated card ids; migration scripts referencing cards from another instance.","solutions":["Verify execution.card refers to an existing card: fetch it via the hierarchy/client (findOne by _id) before running the process, and delete/clean orphaned Execution records.","Fix the workflow/data that created the Execution with a bad card id (e.g. ensure the card is created before the process is started on it).","If the card may legitimately disappear, wrap the process execution in a try/catch for process.error.ObjectNotFound and cancel/skip the execution gracefully.","Check cache population logic if you run UpdateCard with a custom control.cache — ensure the card is loaded before execution."],"exampleFix":"// before\nawait process(UpdateCard, patch) // execution.card may be stale\n// after\nconst card = await client.findOne(core.class.Doc, { _id: execution.card })\nif (card === undefined) {\n  await cancelExecution(execution) // card no longer exists\n  return\n}\nawait process(UpdateCard, patch)","handlingStrategy":"try-catch","validationCode":"const card = await client.findOne(core.class.Doc, { _id: execution.card })\nif (card === undefined) {\n  await cancelExecution(execution) // card gone; do not run UpdateCard\n  return\n}","typeGuard":"async function cardExists(client: Client, id: Ref<Doc> | undefined): id is Ref<Doc> {\n  if (id === undefined) return false\n  return (await client.findOne(core.class.Doc, { _id: id })) !== undefined\n}","tryCatchPattern":"try {\n  await process(UpdateCard, params)\n} catch (err: any) {\n  if (err?.code === 'process.error.ObjectNotFound' && err?._id === execution.card) {\n    await cancelExecution(execution) // stale card; retrying will not help\n    return\n  }\n  throw err\n}","preventionTips":["Do not hard-delete cards that still have pending process executions; cancel executions first.","Resolve execution.card against the DB before running process steps.","Avoid copying Execution records between workspaces/environments.","Monitor for ObjectNotFound spikes as a signal of broken referential integrity."],"tags":["process","object-not-found","stale-reference","data-integrity"],"backgroundTag":"object-not-found","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}