hcengineering/platform · error · Error

sequence object not found

Error message

sequence object not found

What it means

CreateOpinion.svelte looks up the core Sequence object attached to `recruit.class.Review` to generate a sequential number (name) for the new opinion. If no Sequence document exists for Review, the numbering scheme cannot be incremented and the component throws. Sequence objects are normally seeded when the Review class is registered with a numbering pattern.

Source

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

    _id: generateId(),
    collection: 'reviews',
    modifiedOn: Date.now(),
    modifiedBy: '' as PersonId,
    description: '',
    value: ''
  }

  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,

View on GitHub (pinned to 63e28dc964)

Solutions

  1. Create the missing Sequence object for recruit.class.Review (e.g. via the generateSequence helper / plugin setup) in the workspace.
  2. Re-run the sequence generation/upgrade routine so sequences are seeded for all numbered classes.
  3. Instead of throwing, create the sequence lazily: if findOne returns undefined, call createDoc with an initial sequence value.
  4. Verify with a query that a Sequence doc with attachedTo=recruit.class.Review exists in the affected workspace.

Example fix

// before
const sequence = await client.findOne(core.class.Sequence, { attachedTo: recruit.class.Review })
if (sequence === undefined) {
  throw new Error('sequence object not found')
}
// after
let sequence = await client.findOne(core.class.Sequence, { attachedTo: recruit.class.Review })
if (sequence === undefined) {
  sequence = await client.createDoc(core.class.Sequence, core.space.Model, {
    attachedTo: recruit.class.Review,
    sequence: 0
  })
}
Defensive patterns

Strategy: try-catch

Validate before calling

const sequence = await client.findOne(core.class.Sequence, { attachedTo: recruit.class.Review })
if (sequence === undefined) {
  // seed it before proceeding
  await client.createDoc(core.class.Sequence, core.space.Model, { attachedTo: recruit.class.Review, sequence: 0 })
}

Type guard

function hasSequence(s: Sequence | undefined): s is Sequence { return s !== undefined }

Try / catch

try {
  await createOpinion()
} catch (e) {
  if (e.message === 'sequence object not found') {
    await seedSequence(recruit.class.Review)
    await createOpinion()
  } else throw e
}

Prevention

When it happens

Trigger: Calling createOpinion when `client.findOne(core.class.Sequence, { attachedTo: recruit.class.Review })` returns undefined — i.e. the Sequence document for Review was never created in the current workspace or was deleted.

Common situations: Fresh workspaces created before the sequence-seeding migration ran, a backup restore missing sequence documents, deleted Sequence docs from a data cleanup, or a plugin upgrade that renamed the class without migrating sequences.

Related errors


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