mastra-ai/mastra · error · Error
Environment not found: ${envArg}. List environments with: ma
Error message
Environment not found: ${envArg}. List environments with: mastra env list What it means
findEnvironment() resolves envArg against the project's environments by id, name, or slug; when no environment matches it throws with a pointer to `mastra env list`. Used by db subcommands that accept an explicit environment argument.
Source
Thrown at packages/cli/src/commands/db/db.ts:214
async function findDatabase(token: string, orgId: string, project: Project, dbArg: string): Promise<ProjectDatabase> {
const databases = await fetchDatabases(token, orgId, project.id);
const db = databases.find(d => d.id === dbArg || d.name === dbArg);
if (!db) {
throw new Error(`Database not found: ${dbArg}. List databases with: mastra env db list`);
}
return db;
}
/* ------------------------------------------------------------------ */
/* mastra env db list */
/* ------------------------------------------------------------------ */
async function findEnvironment(token: string, orgId: string, project: Project, envArg: string): Promise<Environment> {
const environments = await fetchEnvironments(token, orgId, project.id);
const env = environments.find(e => e.id === envArg || e.name === envArg || e.slug === envArg);
if (!env) {
throw new Error(`Environment not found: ${envArg}. List environments with: mastra env list`);
}
return env;
}
async function listDatabasesAction(envArg: string | undefined, options: { project?: string; json?: boolean }) {
const token = await getToken();
const { orgId } = await resolveCurrentOrg(token);
const project = await resolveProject(token, orgId, options.project);
const [databases, environments] = await Promise.all([
fetchDatabases(token, orgId, project.id),
fetchEnvironments(token, orgId, project.id),
]);
const env = envArg
? (environments.find(e => e.id === envArg || e.name === envArg || e.slug === envArg) ??
(() => {
throw new Error(`Environment not found: ${envArg}. List environments with: mastra env list`);View on GitHub (pinned to 75dd419e61)
Solutions
- Run `mastra env list` and copy the exact environment name/slug.
- Pass `--project <name>` if the environment belongs to another project.
- Verify the environment still exists; recreate with `mastra env create <name>` if it was deleted.
Example fix
// before mastra env db list productoin // after mastra env db list production
Defensive patterns
Strategy: validation
Validate before calling
const envs = await listEnvironments(); // or `mastra env list --json`
if (!envs.some(e => e.id === envArg || e.name === envArg || e.slug === envArg)) {
throw new Error(`Unknown environment "${envArg}" — valid: ${envs.map(e => e.slug).join(', ')}`);
} Try / catch
try {
await runEnvDbCommand(envArg);
} catch (e) {
if (/Environment not found/.test((e as Error).message)) {
console.error('Run `mastra env list` and use an exact id/name/slug; verify --project.');
}
} Prevention
- Resolve environment names from `mastra env list` rather than memory.
- Include --project in scripts when operating across multiple projects.
- Update scripts after environments are renamed or deleted.
When it happens
Trigger: `mastra env db <cmd> <envArg> ...` where envArg matches no environment id, name, or slug of the resolved project.
Common situations: Typo in environment name, environment belongs to a different project (missing --project), or the environment was deleted/renamed by a teammate.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- Database not found: ${dbArg}. List databases with: mastra en
- Project ${project.name} has no environments. Create one with
- Template "${template}" not found
- Project ${project.name} has multiple environments (${slugs})
- MASTRA_ORG_ID and MASTRA_PROJECT_ID are required when MASTRA
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/ca330426b925f29f.
Report an issue: GitHub.