{"record":{"id":"656f4a2644eecf66","repo":"mastra-ai/mastra","slug":"linearintegration-is-not-initialized-the-factory","errorCode":null,"errorMessage":"LinearIntegration is not initialized — the factory binds storage during prepare().","messagePattern":"LinearIntegration is not initialized — the factory binds storage during prepare\\(\\)\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"mastracode/factory/src/integrations/linear/integration.ts","lineNumber":295,"sourceCode":"\n  /** Bind Linear's slice of the generic integration storage, the projects domain, and the host auth seam. */\n  initialize({\n    storage,\n    projects,\n    auth,\n  }: {\n    storage: IntegrationStorageHandle;\n    projects: FactoryProjectsStorage;\n    auth: RouteAuth;\n  }): void {\n    this.#storage = storage as unknown as LinearStorageHandle;\n    this.#projects = projects;\n    this.#auth = auth;\n  }\n\n  get storage(): LinearStorageHandle {\n    if (!this.#storage) {\n      throw new Error('LinearIntegration is not initialized — the factory binds storage during prepare().');\n    }\n    return this.#storage;\n  }\n\n  /** Factory projects domain — maps a session's resourceId to its owning org. */\n  get projects(): FactoryProjectsStorage {\n    if (!this.#projects) {\n      throw new Error('LinearIntegration is not initialized — the factory binds storage during prepare().');\n    }\n    return this.#projects;\n  }\n\n  /**\n   * Whether the host runs with web auth enabled. Linear connections are\n   * org-owned, so every Linear surface is inert without a tenant auth seam.\n   */\n  get authEnabled(): boolean {\n    return this.#auth?.enabled() ?? false;","sourceCodeStart":277,"sourceCodeEnd":313,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/mastracode/factory/src/integrations/linear/integration.ts#L277-L313","documentation":"The `storage` getter on `LinearIntegration` throws when the private `#storage` field has not been bound. The factory is expected to call `initialize()` (during its `prepare()` phase) with the integration storage handle, projects domain, and auth seam before any Linear surface runs. Accessing `integration.storage` directly before that lifecycle step runs fails fast with this message.","triggerScenarios":"Reading `linearIntegration.storage` (directly or via methods like `loadConnection`/`upsertConnection`) on an instance that was constructed but never passed through the factory's `prepare()`/`initialize()` flow — e.g. instantiating `LinearIntegration` standalone in a script or test.","commonSituations":"Hand-rolling a `new LinearIntegration(...)` outside the factory bootstrap; test setups that skip factory initialization; calling storage-backed methods in module top-level code that runs before `prepare()` resolves; reordering bootstrap so a route handler fires before the factory binds storage.","solutions":["Run the factory's normal bootstrap/prepare flow before using any LinearIntegration surface.","If constructing standalone, call `integration.initialize({ storage, projects, auth })` yourself with valid handles.","In tests, use the factory's prepare helper or a fixture that performs initialization.","Ensure `await` on factory startup before serving requests that touch Linear."],"exampleFix":"// before\nconst integration = new LinearIntegration({ clientId, clientSecret });\nawait integration.loadConnection(orgId); // throws\n// after\nconst integration = new LinearIntegration({ clientId, clientSecret });\nintegration.initialize({ storage, projects, auth });\nawait integration.loadConnection(orgId);","handlingStrategy":"validation","validationCode":"function assertInitialized(integration: LinearIntegration): void {\n  // storage getter throws if #storage is unbound; touch it eagerly at startup\n  void integration.storage; // throws the fast-fail error before serving traffic\n}\n// Call right after factory prepare():\nassertInitialized(integration);","typeGuard":null,"tryCatchPattern":"try {\n  await integration.loadConnection(orgId);\n} catch (err) {\n  if (err instanceof Error && err.message.includes('is not initialized')) {\n    throw new Error('Bootstrap bug: factory prepare() must run initialize() before Linear surfaces are used');\n  }\n  throw err;\n}","preventionTips":["Always construct LinearIntegration through the factory bootstrap, never standalone in production code.","Touch storage/projects getters once at startup to fail fast on wiring bugs.","In tests, reuse the factory's prepare helper instead of manual instantiation.","Order bootstrap so `await factory.prepare()` completes before serving requests."],"tags":["lifecycle","initialization","configuration"],"backgroundTag":"integration-not-initialized","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}