{"record":{"id":"3420500e61dc4091","repo":"mastra-ai/mastra","slug":"factory-project-not-found-for-this-organization","errorCode":null,"errorMessage":"Factory project not found for this organization.","messagePattern":"Factory project not found for this organization\\.","errorType":"exception","errorClass":null,"httpStatus":404,"severity":"error","filePath":"mastracode/factory/src/storage/domains/source-control/base.ts","lineNumber":746,"sourceCode":"          const project = await db().findOne<Record<string, unknown>>(FACTORY_PROJECTS, {\n            id: factoryProjectId,\n            org_id: orgId,\n          });\n          if (!project) return [];\n          return (\n            await db().findMany<ConnectionDbRow>(CONNECTIONS, {\n              factory_project_id: factoryProjectId,\n              integration_id: integrationId,\n            })\n          ).map(toConnection);\n        },\n        get: getConnection,\n        create: async input => {\n          const project = await db().findOne<Record<string, unknown>>(FACTORY_PROJECTS, {\n            id: input.factoryProjectId,\n            org_id: input.orgId,\n          });\n          if (!project) throw new Error('Factory project not found for this organization.');\n          await requireInstallation({ orgId: input.orgId, id: input.installationId });\n          try {\n            const row = await db().insertOne<ConnectionDbRow>(CONNECTIONS, {\n              factory_project_id: input.factoryProjectId,\n              integration_id: integrationId,\n              installation_id: input.installationId,\n              created_by_user_id: input.createdByUserId,\n              created_at: new Date(),\n            });\n            return toConnection(row);\n          } catch (error) {\n            if (!(error instanceof UniqueViolationError)) throw error;\n            const row = await db().findOne<ConnectionDbRow>(CONNECTIONS, {\n              factory_project_id: input.factoryProjectId,\n              integration_id: integrationId,\n              installation_id: input.installationId,\n            });\n            if (!row) throw error;","sourceCodeStart":728,"sourceCodeEnd":764,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/mastracode/factory/src/storage/domains/source-control/base.ts#L728-L764","documentation":"Thrown when creating a connection whose input.factoryProjectId does not resolve to a factory project row in the given org. Connections must reference an existing factory project within the same organization.","triggerScenarios":"Calling connections.create with a factoryProjectId from another org, a deleted project, or a mistyped/nonexistent id.","commonSituations":"Cross-environment IDs (staging vs production); project deleted before linking; copying seed data between orgs.","solutions":["Verify the factory project exists in the same org before creating the connection","Create the factory project first if it does not exist","Check that input.orgId matches the project's org_id"],"exampleFix":"// before\nawait forIntegration.connections.create({ orgId, factoryProjectId: projectId, installationId });\n// after\nconst project = await factoryProjects.get({ orgId, id: projectId });\nif (!project) throw new Error(`Create project ${projectId} first`);\nawait forIntegration.connections.create({ orgId, factoryProjectId: projectId, installationId });","handlingStrategy":"validation","validationCode":"const project = await db().findOne(FACTORY_PROJECTS, { id: factoryProjectId, org_id: orgId });\nif (!project) throw new Error(`Factory project ${factoryProjectId} does not exist in org ${orgId}`);","typeGuard":"function hasFactoryProject(\n  p: { id: string; org_id: string } | null,\n  orgId: string\n): p is { id: string; org_id: string } {\n  return p !== null && p.org_id === orgId;\n}","tryCatchPattern":"try {\n  await connections.create(input);\n} catch (e) {\n  if (e instanceof Error && e.message.includes('Factory project not found')) {\n    await createFactoryProject({ orgId, id: input.factoryProjectId });\n    await connections.create(input);\n  } else throw e;\n}","preventionTips":["Create factory projects before wiring connections","Never reuse ids across environments/orgs","Check project org_id equals input.orgId"],"tags":["source-control","not-found","factory-project","connection"],"backgroundTag":"resource-not-found","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}