mastra-ai/mastra · error
LinearIntegration is not initialized — the factory binds sto
Error message
LinearIntegration is not initialized — the factory binds storage during prepare().
What it means
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.
Source
Thrown at mastracode/factory/src/integrations/linear/integration.ts:295
/** Bind Linear's slice of the generic integration storage, the projects domain, and the host auth seam. */
initialize({
storage,
projects,
auth,
}: {
storage: IntegrationStorageHandle;
projects: FactoryProjectsStorage;
auth: RouteAuth;
}): void {
this.#storage = storage as unknown as LinearStorageHandle;
this.#projects = projects;
this.#auth = auth;
}
get storage(): LinearStorageHandle {
if (!this.#storage) {
throw new Error('LinearIntegration is not initialized — the factory binds storage during prepare().');
}
return this.#storage;
}
/** Factory projects domain — maps a session's resourceId to its owning org. */
get projects(): FactoryProjectsStorage {
if (!this.#projects) {
throw new Error('LinearIntegration is not initialized — the factory binds storage during prepare().');
}
return this.#projects;
}
/**
* Whether the host runs with web auth enabled. Linear connections are
* org-owned, so every Linear surface is inert without a tenant auth seam.
*/
get authEnabled(): boolean {
return this.#auth?.enabled() ?? false;View on GitHub (pinned to 75dd419e61)
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.
Example fix
// before
const integration = new LinearIntegration({ clientId, clientSecret });
await integration.loadConnection(orgId); // throws
// after
const integration = new LinearIntegration({ clientId, clientSecret });
integration.initialize({ storage, projects, auth });
await integration.loadConnection(orgId); Defensive patterns
Strategy: validation
Validate before calling
function assertInitialized(integration: LinearIntegration): void {
// storage getter throws if #storage is unbound; touch it eagerly at startup
void integration.storage; // throws the fast-fail error before serving traffic
}
// Call right after factory prepare():
assertInitialized(integration); Try / catch
try {
await integration.loadConnection(orgId);
} catch (err) {
if (err instanceof Error && err.message.includes('is not initialized')) {
throw new Error('Bootstrap bug: factory prepare() must run initialize() before Linear surfaces are used');
}
throw err;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Browser not launched
- SlackProvider not attached to Mastra. Call __attach() first.
- GithubIntegration storage has not been initialized.
- GithubIntegration source-control storage has not been initia
- IssueReconcileWorker: call init() before start()
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/656f4a2644eecf66.
Report an issue: GitHub.