hcengineering/platform · error · ProcessError

process.error.RelationNotExists

process.error.RelationNotExists

Error message

Relation not exists: {association}

What it means

Thrown when the association referenced by the relation context (context.association, after resolveAttributeId) does not resolve to an object in the model. The library needs the association definition to determine target class and direction, so it throws RelationNotExists.

Source

Thrown at server-plugins/process-resources/src/utils.ts:192

    throw processError(
      process.error.EmptyRelatedObjectValue,
      {},
      { parent: attr.label, attr: nested?.label ?? getEmbeddedLabel(context.key) }
    )
  }
  return val
}

async function getRelationValue (
  control: ProcessControl,
  execution: Execution,
  context: SelectedRelation
): Promise<any> {
  const _process = control.client.getModel().findObject(execution.process)
  if (_process === undefined) throw processError(process.error.ObjectNotFound, { _id: execution.process })
  const realAssociation = resolveAttributeId(_process, context.association)
  const assoc = control.client.getModel().findObject(realAssociation)
  if (assoc === undefined) throw processError(process.error.RelationNotExists, {})
  const targetClass = context.direction === 'A' ? assoc.classA : assoc.classB
  const q = context.direction === 'A' ? { docB: execution.card } : { docA: execution.card }
  const relations = await control.client.findAll(core.class.Relation, { association: assoc._id, ...q })
  const name = context.direction === 'A' ? assoc.nameA : assoc.nameB
  const shouldBeArray = assoc.type === 'N:N' || (assoc.type === '1:N' && context.direction === 'A')
  if (relations.length === 0) {
    if (shouldBeArray) return []
    throw processError(process.error.RelatedObjectNotFound, { attr: name })
  }
  const ids = relations.map((it) => {
    return context.direction === 'A' ? it.docA : it.docB
  })
  const target = await control.client.findAll(targetClass, { _id: { $in: ids } })
  if (target.length === 0) throw processError(process.error.RelatedObjectNotFound, { attr: context.name })
  const realKey = resolveAttributeId(_process, context.key)
  const attr = realKey !== '' ? control.client.getHierarchy().findAttribute(targetClass, realKey) : undefined
  if (context.sourceFunction !== undefined) {
    const transform = control.client.getModel().findObject(context.sourceFunction.func)

View on GitHub (pinned to 63e28dc964)

Solutions

  1. Verify the association id in the process template exists in the model and fix the reference
  2. Recreate the association definition (or re-import the plugin that defines it)
  3. Re-select the association in the process builder so the correct id is stored
  4. Sync model definitions between environments to include the association

Example fix

// before
association: 'assoc.project-old' // removed
// after
association: 'assoc.project-task' // existing association id
Defensive patterns

Strategy: validation

Validate before calling

const realAssociation = resolveAttributeId(_process, ctx.association)
if (control.client.getModel().findObject(realAssociation) === undefined) {
  throw new Error(`Association ${ctx.association} does not exist`)
}

Type guard

function associationExists(model: Model, associationId: string): boolean {
  return model.findObject(associationId) !== undefined
}

Try / catch

try {
  val = await getRelationValue(control, execution, ctx)
} catch (err) {
  if ((err as any)?.code === 'process.error.RelationNotExists') {
    throw new Error(`Configured association missing: ${ctx.association}`)
  }
  throw err
}

Prevention

When it happens

Trigger: getRelationValue: resolveAttributeId(_process, context.association) returns an id for which control.client.getModel().findObject returns undefined.

Common situations: Association removed/renamed while the process template still selects it; template exported from a workspace without the association; id typo or wrong association id configured in the activity.

Related errors


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