{"record":{"id":"3ef20a354ef19870","repo":"hcengineering/platform","slug":"adapter-manager-should-be-configured","errorCode":null,"errorMessage":"Adapter manager should be configured","messagePattern":"Adapter manager should be configured","errorType":"error_code","errorClass":"PlatformError","httpStatus":null,"severity":"error","filePath":"foundations/server/packages/middleware/src/model.ts","lineNumber":104,"sourceCode":"    return allUserTxes.filter((it) => !isAccountTx(it as TxCUD<Doc>))\n  }\n\n  findAll<T extends Doc>(\n    ctx: MeasureContext<SessionData>,\n    _class: Ref<Class<T>>,\n    query: DocumentQuery<T>,\n    options?: FindOptions<T>\n  ): Promise<FindResult<T>> {\n    const d = this.context.hierarchy.findDomain(_class)\n    if (d === DOMAIN_MODEL) {\n      return this.context.modelDb.findAll(_class, query, options)\n    }\n    return this.provideFindAll(ctx, _class, query, options)\n  }\n\n  async init (ctx: MeasureContext): Promise<void> {\n    if (this.context.adapterManager == null) {\n      throw new PlatformError(unknownError('Adapter manager should be configured'))\n    }\n    const txAdapter = this.context.adapterManager.getAdapter(DOMAIN_TX, true) as TxAdapter\n\n    const userTx = await this.getUserTx(ctx, txAdapter)\n    const model = this.systemTx.concat(userTx)\n    for (const tx of model) {\n      try {\n        this.context.hierarchy.tx(tx)\n      } catch (err: any) {\n        ctx.warn('failed to apply model transaction, skipping', { tx: JSON.stringify(tx), err })\n      }\n    }\n    const fmodel = this.filter !== undefined ? this.filter(this.context.hierarchy, model) : model\n    this.context.modelDb.addTxes(ctx, fmodel, true)\n\n    this.setModel(fmodel)\n  }\n","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/foundations/server/packages/middleware/src/model.ts#L86-L122","documentation":"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').","triggerScenarios":"Calling init() (directly or via doCreate during Model.create) on a pipeline whose PipelineContext lacks adapterManager; loading the model before adapters are registered.","commonSituations":"Server bootstrapping with missing database configuration; building a pipeline without the adapter-manager middleware; tests constructing Model middleware against a bare context.","solutions":["Assign context.adapterManager (AdapterManager middleware or manual construction) before Model.init()/create","Ensure DOMAIN_TX adapter configuration is present in the storage config","Verify middleware ordering so the adapter manager exists before model initialization"],"exampleFix":"// before\nconst model = await Model.create(ctx, context, ...) // context.adapterManager == null\n// after\ncontext.adapterManager = new AdapterManager(ctx, config)\nawait context.adapterManager.init()\nconst model = await Model.create(ctx, context, ...)","handlingStrategy":"validation","validationCode":"if (context.adapterManager == null) {\n  throw new Error('AdapterManager must be configured before Model.init')\n}","typeGuard":"function canInitModel(ctx: PipelineContext): ctx is PipelineContext & { adapterManager: AdapterManager } {\n  return ctx.adapterManager != null\n}","tryCatchPattern":"try {\n  await model.init(ctx)\n} catch (err) {\n  if (isPlatformErrorWith(err, 'Adapter manager should be configured')) {\n    throw new Error('configure AdapterManager before model init')\n  }\n  throw err\n}","preventionTips":["Configure storage/adapter settings at service bootstrap","Initialize AdapterManager before any middleware that needs it","Cover pipeline construction with an integration test","Fail fast at config load if DB settings are missing"],"tags":["configuration","model","middleware"],"backgroundTag":"missing-pipeline-dependency","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}