{"record":{"id":"9413e70d402e8f58","repo":"mastra-ai/mastra","slug":"environment-not-found-envarg","errorCode":null,"errorMessage":"Environment not found: ${envArg}","messagePattern":"Environment not found: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/cli/src/commands/env/vars.ts","lineNumber":44,"sourceCode":"\nfunction isAlreadyExistsError(error: unknown): boolean {\n  return typeof error === 'object' && error !== null && 'code' in error && error.code === 'EEXIST';\n}\n\nfunction pickEnvironment(environments: Environment[], envArg: string | undefined): Environment {\n  if (environments.length === 0) {\n    throw new Error('No environments found for this project. Deploy first with `mastra deploy`.');\n  }\n\n  if (!envArg) {\n    if (environments.length === 1) return environments[0]!;\n    const slugs = environments.map(e => e.slug).join(', ');\n    throw new Error(`Multiple environments found (${slugs}). Specify one: mastra env vars pull <environment>`);\n  }\n\n  const env = environments.find(e => e.id === envArg || e.name === envArg || e.slug === envArg);\n  if (!env) {\n    throw new Error(`Environment not found: ${envArg}`);\n  }\n  return env;\n}\n\n/**\n * Pull the full set of env vars that a deploy of the target environment\n * actually runs with — the environment row's vars (e.g. added via the UI\n * editor) merged with the project-scoped vars, with project values winning on\n * conflict, matching the platform's deploy-time merge precedence. Managed\n * vars (platform-injected secrets) are listed as comments, names only.\n *\n * The legacy `mastra server env pull` reads only the project scope; this is\n * the unified-surface replacement that fixes UI-added vars silently missing\n * from pulled files.\n */\nexport async function envVarsPullAction(\n  envArg: string | undefined,\n  options: { project?: string; output?: string; force?: boolean },","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/cli/src/commands/env/vars.ts#L26-L62","documentation":"The `mastra env vars pull` command resolves an environment by exact match on id, name, or slug against the environments fetched for the linked project. This error is thrown when the user-supplied environment argument matches none of the project's environments. It indicates a typo, a stale reference, or that the environment belongs to a different project/organization.","triggerScenarios":"Running `mastra env vars pull <environment>` where <environment> does not exactly (case-sensitively) match the id, name, or slug of any environment returned by fetchEnvironments for the resolved project.","commonSituations":"Typo or wrong casing in the environment slug (matching is exact, not fuzzy); the environment was deleted or renamed; the environment belongs to a different project than the linked one; `--project` was omitted so the wrong linked project was resolved; being authenticated into a different org.","solutions":["Run `mastra env vars pull` with no argument: if the project has exactly one environment it is picked automatically; otherwise the error lists all valid slugs — copy one exactly.","Check for typos/case and re-run with the exact slug or ID, e.g. `mastra env vars pull production`.","Verify the environment belongs to the intended project by passing `--project <project>` explicitly.","If the environment was renamed or deleted, update your scripts or recreate the environment and redeploy with `mastra deploy`."],"exampleFix":"// before\nmastra env vars pull Production\n// after\nmastra env vars pull production   # exact slug, from the list printed by the multiple-environments error","handlingStrategy":"validation","validationCode":"const envs = await fetchEnvironments(token, orgId, project.id);\nif (envArg && !envs.some(e => e.id === envArg || e.name === envArg || e.slug === envArg)) {\n  throw new Error(`Unknown environment '${envArg}'. Valid: ${envs.map(e => e.slug).join(', ')}`);\n}","typeGuard":"null","tryCatchPattern":"null","preventionTips":["List available slugs by running the command without an argument first","Copy/paste slugs or IDs from the CLI output instead of typing them","Pin the environment slug in scripts/CI rather than passing freeform values","Verify the linked project/org before invoking with --project"],"tags":["cli","environment-resolution","user-input"],"backgroundTag":"environment-not-found","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}