{"record":{"id":"5078ef83a8bb13da","repo":"mastra-ai/mastra","slug":"source-control-repository-not-found-for-this-organ","errorCode":null,"errorMessage":"Source-control repository not found for this organization and integration.","messagePattern":"Source-control repository not found for this organization and integration\\.","errorType":"exception","errorClass":null,"httpStatus":404,"severity":"error","filePath":"mastracode/factory/src/storage/domains/source-control/base.ts","lineNumber":572,"sourceCode":"      return row ? toInstallation(row) : null;\n    };\n\n    const requireInstallation = async (args: { orgId: string; id: string }): Promise<SourceControlInstallation> => {\n      const installation = await getInstallation(args);\n      if (!installation)\n        throw new Error('Source-control installation not found for this organization and integration.');\n      return installation;\n    };\n\n    const getRepository = async (args: { orgId: string; id: string }): Promise<SourceControlRepository | null> => {\n      const row = await db().findOne<RepositoryDbRow>(REPOSITORIES, { id: args.id });\n      if (!row || !(await getInstallation({ orgId: args.orgId, id: row.installation_id }))) return null;\n      return toRepository(row);\n    };\n\n    const requireRepository = async (args: { orgId: string; id: string }): Promise<SourceControlRepository> => {\n      const repository = await getRepository(args);\n      if (!repository) throw new Error('Source-control repository not found for this organization and integration.');\n      return repository;\n    };\n\n    const getConnection = async (args: {\n      orgId: string;\n      id: string;\n    }): Promise<ProjectSourceControlConnection | null> => {\n      const row = await db().findOne<ConnectionDbRow>(CONNECTIONS, { id: args.id, integration_id: integrationId });\n      if (!row) return null;\n      const project = await db().findOne<Record<string, unknown>>(FACTORY_PROJECTS, {\n        id: row.factory_project_id,\n        org_id: args.orgId,\n      });\n      if (!project || !(await getInstallation({ orgId: args.orgId, id: row.installation_id }))) return null;\n      return toConnection(row);\n    };\n\n    const requireConnection = async (args: { orgId: string; id: string }): Promise<ProjectSourceControlConnection> => {","sourceCodeStart":554,"sourceCodeEnd":590,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/mastracode/factory/src/storage/domains/source-control/base.ts#L554-L590","documentation":"Thrown by requireRepository when no repository row exists for the given orgId and id, or when its parent installation no longer exists (getRepository returns null if the installation lookup fails). The factory refuses to hand back a repository object that is not backed by both a row and a live installation.","triggerScenarios":"Calling repository require via requireRepository/repository with an id that was never created, a repository belonging to a different org, or a repository whose installation was deleted (so getInstallation returns falsy).","commonSituations":"Stale repository IDs cached by callers after an installation was uninstalled/revoked; referencing a repo across orgs; typos in repository IDs; repositories created under a different source-control integration.","solutions":["Verify the repository id and orgId are correct and the repository exists under this integration","Re-create the repository (upsertRepository) or re-link it before calling requireRepository","Check that the GitHub/App installation still exists (getInstallation) and reinstall if it was revoked","Ensure you are not mixing repositories across organizations"],"exampleFix":"// before\nconst repo = await sourceControl.repository.require({ orgId, id: maybeStaleId });\n// after\nconst existing = await sourceControl.repository.get({ orgId, id: maybeStaleId });\nif (!existing) {\n  const created = await sourceControl.repository.upsert({ orgId, installationId, externalId, name });\n}","handlingStrategy":"try-catch","validationCode":"const repo = await integration.repositories?.get?.({ orgId, id });\nif (!repo) throw new Error(`Repository ${id} missing; upsert it first`);","typeGuard":"function isRepository(v: unknown): v is SourceControlRepository {\n  return !!v && typeof v === 'object' && 'id' in v && 'installationId' in v;\n}","tryCatchPattern":"try {\n  repo = await requireRepository({ orgId, id });\n} catch (e) {\n  if (e instanceof Error && e.message.includes('repository not found')) {\n    repo = await upsertRepository({ orgId, installationId, externalId, name });\n  } else throw e;\n}","preventionTips":["Always call get before require for optional lookups","Keep installation and repository lifecycles in sync (reinstall cascades)","Cache repository ids per org, never across orgs","Re-fetch ids after any integration reset"],"tags":["source-control","not-found","repository"],"backgroundTag":"resource-not-found","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}