hcengineering/platform · error · Error

contact not found

Error message

contact not found

What it means

After incrementing the sequence, CreateOpinion.svelte fetches the parent Review document via `doc.attachedTo`. If that findOne returns undefined, the opinion cannot be attached to a review/space and the component throws — misleadingly labeled 'contact not found'. This indicates the opinion's attachedTo reference points at a review that no longer exists (or was never loaded).

Source

Thrown at plugins/recruit-resources/src/components/review/CreateOpinion.svelte:64

  const dispatch = createEventDispatcher()
  const client = getClient()

  export function canClose (): boolean {
    return review === undefined && assignee === undefined
  }

  async function createOpinion () {
    const sequence = await client.findOne(core.class.Sequence, { attachedTo: recruit.class.Review })
    if (sequence === undefined) {
      throw new Error('sequence object not found')
    }

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

    const reviewInstance = await client.findOne(recruit.class.Review, { _id: doc.attachedTo })
    if (reviewInstance === undefined) {
      throw new Error('contact not found')
    }

    await client.addCollection(
      recruit.class.Opinion,
      reviewInstance.space,
      doc.attachedTo,
      doc.attachedToClass,
      'opinions',
      {
        number: (incResult as any).object.sequence,
        description: doc.description,
        value: doc.value
      }
    )
  }
</script>

<Card

View on GitHub (pinned to 63e28dc964)

Solutions

  1. Refresh the client data and retry — the review may have been deleted or the cache is stale.
  2. Fix the misleading message: log/throw with the actual doc.attachedTo id to debug which reference is broken.
  3. Validate before opening the dialog that doc.attachedTo resolves to an existing Review.
  4. Check current user's permissions — the review may exist but be invisible to this account.

Example fix

// before
const reviewInstance = await client.findOne(recruit.class.Review, { _id: doc.attachedTo })
if (reviewInstance === undefined) {
  throw new Error('contact not found')
}
// after
const reviewInstance = await client.findOne(recruit.class.Review, { _id: doc.attachedTo })
if (reviewInstance === undefined) {
  throw new Error(`review not found: ${String(doc.attachedTo)}`)
}
Defensive patterns

Strategy: type-guard

Validate before calling

const review = await client.findOne(recruit.class.Review, { _id: doc.attachedTo })
if (review === undefined) {
  console.error('review missing', doc.attachedTo)
  return
}

Type guard

function reviewExists(r: Review | undefined): r is Review { return r !== undefined }

Try / catch

try {
  await createOpinion()
} catch (e) {
  if (e.message === 'contact not found') {
    await refreshClient()
    showNotification('The review no longer exists')
  } else throw e
}

Prevention

When it happens

Trigger: Creating an opinion from a doc whose `attachedTo` id does not resolve to a recruit.class.Review document: the review was deleted concurrently, the id is stale in the client-side cache, or the doc was created against the wrong class.

Common situations: Another user deleted the review while the opinion dialog was open; stale client data after offline edits; opening the dialog from a non-Review document due to a UI routing bug; permission filtering hiding the review from the current user.

Related errors


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