mastra-ai/mastra · error
No organization matched --org "${value}". Available: ${avail
Error message
No organization matched --org "${value}". Available: ${available}. What it means
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.
Source
Thrown at mastracode/mastra-factory/src/create.ts:389
return { orgId, orgName, project, secretKey, databaseUrl };
} finally {
// Best-effort partial write on failure so a successful `sk_` mint or
// project-id isn't thrown away when a later step blows up.
flush();
}
}
/**
* `--org <value>` matches by org id or exact name. Not a substring match —
* an ambiguous or non-existent value bails with a clear message instead of
* silently picking the wrong org.
*/
async function resolveOrgFromFlag(token: string, value: string): Promise<{ orgId: string; orgName: string }> {
const orgs = await fetchOrgs(token);
const match = orgs.find(o => o.id === value || o.name === value);
if (!match) {
const available = orgs.map(o => `${o.name} (${o.id})`).join(', ') || '(none)';
throw new Error(`No organization matched --org "${value}". Available: ${available}.`);
}
return { orgId: match.id, orgName: match.name };
}
/**
* Neon display-name charset: `[a-zA-Z0-9_-]+`, up to 64 chars. Drop anything
* outside that, and clip length.
*/
function sanitizeDatabaseName(projectName: string): string {
const cleaned = projectName.replace(/[^a-zA-Z0-9_-]/g, '-').replace(/^-+|-+$/g, '');
const truncated = (cleaned || 'factory').slice(0, 64);
return truncated;
}
/**
* Append `.env` to the scaffolded project's `.gitignore` if it isn't already
* ignored. Runs before the initial `git add -A` so freshly-provisioned platform
* credentials (MASTRA_PLATFORM_SECRET_KEY, DATABASE_URL) never reach theView on GitHub (pinned to 75dd419e61)
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.
Example fix
// before pnpm create-factory --org "Acme Inc" // actual name is "acme-inc" // after pnpm create-factory --org "acme-inc" // or --org "org_2aBcDeFgHiJkLm"
Defensive patterns
Strategy: validation
Validate before calling
const orgs = await fetchOrgs(token);
const norm = s => s.trim().toLowerCase();
const match = orgs.find(o => o.id === value || norm(o.name) === norm(value));
if (!match) {
console.error('Available orgs:', orgs.map(o => `${o.name} (${o.id})`).join(', '));
process.exit(1);
} Try / catch
try {
const { orgId, orgName } = await resolveOrgFromFlag(token, orgFlag);
} catch (err) {
if (err.message.startsWith('No organization matched')) {
console.error(err.message + '\nCopy an id exactly from the Available list, or re-login with the right account.');
process.exit(1);
}
throw err;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Invalid --region "${region}". Expected one of: eu, us.
- No access to organization ${orgId}. Run: mastra auth orgs
- You have no organizations. Please create one at ${MASTRA_STU
- Found ${projects.length} existing project(s) in this organiz
- Could not determine project name from package.json. Use --pr
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/3254e523af35c275.
Report an issue: GitHub.