hcengineering/platform · error · Error

contact not found

Error message

contact not found

What it means

Thrown in CreateApplication.svelte when the candidate lookup fails: client.findOne(contact.class.Person, {_id: _candidate}) returns undefined. The Person instance is required to check/apply the recruit.mixin.Candidate mixin and link the application.

Source

Thrown at plugins/recruit-resources/src/components/CreateApplication.svelte:133

  }

  async function createApplication (): Promise<void> {
    if (selectedState === undefined) {
      throw new Error(`Please select initial state:${_space}`)
    }
    const sequence = await client.findOne(core.class.Sequence, { attachedTo: recruit.class.Applicant })
    if (sequence === undefined) {
      throw new Error('sequence object not found')
    }
    if (kind === undefined) {
      throw new Error('kind is not specified')
    }

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

    const candidateInstance = await client.findOne(contact.class.Person, { _id: _candidate })
    if (candidateInstance === undefined) {
      throw new Error('contact not found')
    }

    const ops = client.apply(undefined, recruitId + '.Create.CreateApplication')

    if (!client.getHierarchy().hasMixin(candidateInstance, recruit.mixin.Candidate)) {
      await ops.createMixin<Contact, Candidate>(
        candidateInstance._id,
        candidateInstance._class,
        candidateInstance.space,
        recruit.mixin.Candidate,
        {}
      )
    }

    const number = (incResult as any).object.sequence

    await ops.addCollection(
      recruit.class.Applicant,

View on GitHub (pinned to 63e28dc964)

Solutions

  1. Re-select the candidate in the dialog and retry
  2. Confirm the person exists via client.findOne before opening the application form
  3. Refresh client data / reconnect to sync deletions
  4. Catch the error and ask the user to pick a different candidate

Example fix

// before
const candidateInstance = await client.findOne(contact.class.Person, { _id: _candidate })
if (candidateInstance === undefined) {
  throw new Error('contact not found')
}
// after
if (_candidate === undefined) return
const candidateInstance = await client.findOne(contact.class.Person, { _id: _candidate })
if (candidateInstance === undefined) {
  ui.notify('Selected candidate no longer exists. Please choose another person.')
  return
}
Defensive patterns

Strategy: validation

Validate before calling

if (_candidate === undefined) return
const person = await client.findOne(contact.class.Person, { _id: _candidate })
if (person === undefined) {
  ui.notify('Candidate not found; please reselect.')
  return
}

Type guard

function isPerson (p: Person | undefined): p is Person {
  return p !== undefined
}

Try / catch

try {
  await createApplication()
} catch (err) {
  if (err instanceof Error && err.message === 'contact not found') {
    ui.notify('The selected candidate was deleted. Pick another one.')
  } else throw err
}

Prevention

When it happens

Trigger: _candidate holds a Ref<Person> that does not resolve: candidate deleted before submission, invalid id passed into the dialog, or client not synced with the workspace containing that person.

Common situations: Candidate removed by another user while the application dialog is open; stale list data; wrong ref type passed (Contact vs Person) so lookup misses.

Related errors


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