hcengineering/platform · error · Error

contact not found

Error message

contact not found

What it means

Thrown in CreateLead.svelte when the customer contact lookup fails: client.findOne(contact.class.Contact, {_id: customer}) returns undefined. The code needs the Contact instance to check/apply the lead.mixin.Customer mixin before finishing lead creation.

Source

Thrown at plugins/lead-resources/src/components/CreateLead.svelte:113

    const incResult = await client.update(sequence, { $inc: { sequence: 1 } }, true)
    const number = (incResult as any).object.sequence

    const value: AttachedData<Lead> = {
      status: state,
      number,
      identifier: `LEAD-${number}`,
      title,
      kind,
      rank: '',
      assignee: null,
      startDate: null,
      dueDate: null,
      ...object
    }

    const customerInstance = await client.findOne(contact.class.Contact, { _id: customer })
    if (customerInstance === undefined) {
      throw new Error('contact not found')
    }
    if (!client.getHierarchy().hasMixin(customerInstance, lead.mixin.Customer)) {
      await client.createMixin<Contact, Customer>(
        customerInstance._id,
        customerInstance._class,
        customerInstance.space,
        lead.mixin.Customer,
        { customerDescription: null }
      )
    }

    await client.addCollection(lead.class.Lead, _space, customer, lead.mixin.Customer, 'leads', value, leadId)
    Analytics.handleEvent(LeadEvents.LeadCreated, { id: `LEAD-${number}`, customer })
    dispatch('close')
  }

  const manager = createFocusManager()

View on GitHub (pinned to 63e28dc964)

Solutions

  1. Re-select the customer contact in the dialog and retry
  2. Verify the contact still exists (client.findOne) before opening the lead form
  3. Refresh client data / reconnect to pick up deletions
  4. Catch the error and ask the user to choose a different customer

Example fix

// before
const customerInstance = await client.findOne(contact.class.Contact, { _id: customer })
if (customerInstance === undefined) {
  throw new Error('contact not found')
}
// after
if (customer !== undefined) {
  const customerInstance = await client.findOne(contact.class.Contact, { _id: customer })
  if (customerInstance === undefined) {
    ui.notify('Selected customer was deleted. Please choose another contact.')
    return
  }
}
Defensive patterns

Strategy: validation

Validate before calling

if (customer === undefined) return
const contact = await client.findOne(contact.class.Contact, { _id: customer })
if (contact === undefined) {
  ui.notify('Customer contact not found; please reselect.')
  return
}

Type guard

function isContact (c: Contact | undefined): c is Contact {
  return c !== undefined
}

Try / catch

try {
  await createLead()
} catch (err) {
  if (err instanceof Error && err.message === 'contact not found') {
    ui.notify('The chosen customer was deleted. Select another contact.')
  } else throw err
}

Prevention

When it happens

Trigger: The `customer` ref points to a contact that no longer exists, was deleted concurrently, or `customer` holds an invalid id; the contact exists in a different workspace than the client is connected to.

Common situations: Contact deleted by another user while the lead form is open; stale reference passed from a previous screen; account/workspace switch mid-flow.

Related errors


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