hcengineering/platform · error · PlatformError

Adapter manager should be configured

Error message

Adapter manager should be configured

What it means

Model middleware's init() builds the in-memory model from the transaction domain, which requires a TxAdapter obtained from context.adapterManager. When the context has no adapterManager configured it throws unknownError('Adapter manager should be configured').

Source

Thrown at foundations/server/packages/middleware/src/model.ts:104

    return allUserTxes.filter((it) => !isAccountTx(it as TxCUD<Doc>))
  }

  findAll<T extends Doc>(
    ctx: MeasureContext<SessionData>,
    _class: Ref<Class<T>>,
    query: DocumentQuery<T>,
    options?: FindOptions<T>
  ): Promise<FindResult<T>> {
    const d = this.context.hierarchy.findDomain(_class)
    if (d === DOMAIN_MODEL) {
      return this.context.modelDb.findAll(_class, query, options)
    }
    return this.provideFindAll(ctx, _class, query, options)
  }

  async init (ctx: MeasureContext): Promise<void> {
    if (this.context.adapterManager == null) {
      throw new PlatformError(unknownError('Adapter manager should be configured'))
    }
    const txAdapter = this.context.adapterManager.getAdapter(DOMAIN_TX, true) as TxAdapter

    const userTx = await this.getUserTx(ctx, txAdapter)
    const model = this.systemTx.concat(userTx)
    for (const tx of model) {
      try {
        this.context.hierarchy.tx(tx)
      } catch (err: any) {
        ctx.warn('failed to apply model transaction, skipping', { tx: JSON.stringify(tx), err })
      }
    }
    const fmodel = this.filter !== undefined ? this.filter(this.context.hierarchy, model) : model
    this.context.modelDb.addTxes(ctx, fmodel, true)

    this.setModel(fmodel)
  }

View on GitHub (pinned to 63e28dc964)

Solutions

  1. Assign context.adapterManager (AdapterManager middleware or manual construction) before Model.init()/create
  2. Ensure DOMAIN_TX adapter configuration is present in the storage config
  3. Verify middleware ordering so the adapter manager exists before model initialization

Example fix

// before
const model = await Model.create(ctx, context, ...) // context.adapterManager == null
// after
context.adapterManager = new AdapterManager(ctx, config)
await context.adapterManager.init()
const model = await Model.create(ctx, context, ...)
Defensive patterns

Strategy: validation

Validate before calling

if (context.adapterManager == null) {
  throw new Error('AdapterManager must be configured before Model.init')
}

Type guard

function canInitModel(ctx: PipelineContext): ctx is PipelineContext & { adapterManager: AdapterManager } {
  return ctx.adapterManager != null
}

Try / catch

try {
  await model.init(ctx)
} catch (err) {
  if (isPlatformErrorWith(err, 'Adapter manager should be configured')) {
    throw new Error('configure AdapterManager before model init')
  }
  throw err
}

Prevention

When it happens

Trigger: Calling init() (directly or via doCreate during Model.create) on a pipeline whose PipelineContext lacks adapterManager; loading the model before adapters are registered.

Common situations: Server bootstrapping with missing database configuration; building a pipeline without the adapter-manager middleware; tests constructing Model middleware against a bare context.

Related errors


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