{"record":{"id":"3254e523af35c275","repo":"mastra-ai/mastra","slug":"no-organization-matched-org-value-availabl","errorCode":null,"errorMessage":"No organization matched --org \"${value}\". Available: ${available}.","messagePattern":"No organization matched --org \"(.+?)\"\\. Available: (.+?)\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"mastracode/mastra-factory/src/create.ts","lineNumber":389,"sourceCode":"    return { orgId, orgName, project, secretKey, databaseUrl };\n  } finally {\n    // Best-effort partial write on failure so a successful `sk_` mint or\n    // project-id isn't thrown away when a later step blows up.\n    flush();\n  }\n}\n\n/**\n * `--org <value>` matches by org id or exact name. Not a substring match —\n * an ambiguous or non-existent value bails with a clear message instead of\n * silently picking the wrong org.\n */\nasync function resolveOrgFromFlag(token: string, value: string): Promise<{ orgId: string; orgName: string }> {\n  const orgs = await fetchOrgs(token);\n  const match = orgs.find(o => o.id === value || o.name === value);\n  if (!match) {\n    const available = orgs.map(o => `${o.name} (${o.id})`).join(', ') || '(none)';\n    throw new Error(`No organization matched --org \"${value}\". Available: ${available}.`);\n  }\n  return { orgId: match.id, orgName: match.name };\n}\n\n/**\n * Neon display-name charset: `[a-zA-Z0-9_-]+`, up to 64 chars. Drop anything\n * outside that, and clip length.\n */\nfunction sanitizeDatabaseName(projectName: string): string {\n  const cleaned = projectName.replace(/[^a-zA-Z0-9_-]/g, '-').replace(/^-+|-+$/g, '');\n  const truncated = (cleaned || 'factory').slice(0, 64);\n  return truncated;\n}\n\n/**\n * Append `.env` to the scaffolded project's `.gitignore` if it isn't already\n * ignored. Runs before the initial `git add -A` so freshly-provisioned platform\n * credentials (MASTRA_PLATFORM_SECRET_KEY, DATABASE_URL) never reach the","sourceCodeStart":371,"sourceCodeEnd":407,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/mastracode/mastra-factory/src/create.ts#L371-L407","documentation":"resolveOrgFromFlag fetches all organizations for the authenticated token and matches the --org flag value against each org's id or name (exact match). If nothing matches, it throws with the requested value plus a list of available `name (id)` pairs so the user can pick a valid one.","triggerScenarios":"Calling `create-factory --org <value>` where <value> is neither an org id nor an exact org name for the current token — including wrong case, extra whitespace, or the org not belonging to the authenticated user.","commonSituations":"Typo in the org name; passing a display label or slug that differs from the stored name; running with a token from a different account than the one owning the org; the org being renamed since the last run; org membership not yet granted.","solutions":["Re-run with one of the values listed in the error's `Available:` list, copied exactly (name or id).","Use the org id instead of the name — ids are stable and case-exact.","Run `mastra auth login` (or re-authenticate) with the account that belongs to the intended organization, then retry.","Omit --org if there's only one org so the default resolution is used, or list orgs via the platform CLI/dashboard."],"exampleFix":"// before\npnpm create-factory --org \"Acme Inc\"   // actual name is \"acme-inc\"\n// after\npnpm create-factory --org \"acme-inc\"   // or --org \"org_2aBcDeFgHiJkLm\"","handlingStrategy":"validation","validationCode":"const orgs = await fetchOrgs(token);\nconst norm = s => s.trim().toLowerCase();\nconst match = orgs.find(o => o.id === value || norm(o.name) === norm(value));\nif (!match) {\n  console.error('Available orgs:', orgs.map(o => `${o.name} (${o.id})`).join(', '));\n  process.exit(1);\n}","typeGuard":null,"tryCatchPattern":"try {\n  const { orgId, orgName } = await resolveOrgFromFlag(token, orgFlag);\n} catch (err) {\n  if (err.message.startsWith('No organization matched')) {\n    console.error(err.message + '\\nCopy an id exactly from the Available list, or re-login with the right account.');\n    process.exit(1);\n  }\n  throw err;\n}","preventionTips":["Copy org ids, not names, into scripts/CI — ids are exact-match and stable.","Re-authenticate before listing orgs when switching accounts.","Trim/case-normalize org names before matching interactively.","Re-list orgs after any rename or team change."],"tags":["cli","configuration","organization","flag-validation"],"backgroundTag":"invalid-org-flag","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}