{"record":{"id":"8cf16d566012e8d7","repo":"mastra-ai/mastra","slug":"found-projects-length-existing-project-s-in-th","errorCode":null,"errorMessage":"Found ${projects.length} existing project(s) in this organization. Pass --project <id-or-slug> to select one, or re-run without --yes to choose interactively.","messagePattern":"Found (.+?) existing project\\(s\\) in this organization\\. Pass --project <id-or-slug> to select one, or re-run without --yes to choose interactively\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/cli/src/commands/deploy/index.ts","lineNumber":231,"sourceCode":"      existing: true,\n      projectId: projectConfig.projectId,\n      projectName: projectConfig.projectName ?? projectConfig.projectId,\n      projectSlug: projectConfig.projectSlug ?? projectConfig.projectName ?? projectConfig.projectId,\n    };\n  }\n\n  const projects = await fetchProjects(token, orgId);\n  const nameMatches = defaultName\n    ? projects.filter(proj => proj.name === defaultName || proj.slug === defaultName)\n    : [];\n\n  if (projects.length > 0) {\n    if (autoAccept) {\n      if (nameMatches.length === 1) {\n        const m = nameMatches[0]!;\n        return { existing: true, projectId: m.id, projectName: m.name, projectSlug: m.slug ?? m.name };\n      }\n      throw new Error(\n        `Found ${projects.length} existing project(s) in this organization. Pass --project <id-or-slug> to select one, or re-run without --yes to choose interactively.`,\n      );\n    }\n\n    const CREATE_NEW = '__create_new__';\n    const initialValue = nameMatches.length === 1 ? nameMatches[0]!.id : projects[0]!.id;\n    const selected = await p.select({\n      message: 'Select a project to deploy to',\n      initialValue,\n      options: [\n        ...projects.map(proj => ({\n          value: proj.id,\n          label: `${proj.name} (${proj.id})`,\n        })),\n        { value: CREATE_NEW, label: defaultName ? `＋ Create new project \"${defaultName}\"` : '＋ Create new project' },\n      ],\n    });\n","sourceCodeStart":213,"sourceCodeEnd":249,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/cli/src/commands/deploy/index.ts#L213-L249","documentation":"When deploying with --yes (auto-accept) and the organization already contains projects, resolveProject cannot silently pick a target. It only auto-selects when exactly one project matches the package name; otherwise it throws, telling you to pass --project <id-or-slug> or drop --yes for an interactive picker. This prevents accidental deploys to the wrong existing project.","triggerScenarios":"Deploy invoked with --yes where projects.length > 0 and either zero or multiple name matches exist (nameMatches.length !== 1) — i.e., ambiguity between existing projects that auto-accept cannot resolve.","commonSituations":"CI pipelines with --yes where package.json name doesn't match any existing project, or matches several; reusing one org for many similarly-named services; renamed package.json so the name no longer matches the intended project.","solutions":["Pass --project <id-or-slug> explicitly to pin the target project","Re-run without --yes and select the project interactively","Rename the project entry in package.json to exactly match the intended existing project so auto-selection works","In CI, hardcode the project id/slug in the deploy command rather than relying on name matching"],"exampleFix":"// before\nmastra deploy --yes  // 3 projects, name matches 0 -> error\n// after\nmastra deploy --yes --project my-service-slug","handlingStrategy":"validation","validationCode":"// Pin the target project explicitly in non-interactive contexts\nif (autoAccept && !opts.project) {\n  throw new Error('Pass --project <id-or-slug> when using --yes with existing projects in the org');\n}","typeGuard":"function hasSingleNameMatch(nameMatches: Array<{ id: string }>): nameMatches is [ { id: string } ] {\n  return nameMatches.length === 1;\n}","tryCatchPattern":"try {\n  await deploy(opts);\n} catch (err) {\n  if (err instanceof Error && err.message.includes('existing project(s)')) {\n    console.error('Re-run with --project <id-or-slug> or omit --yes to choose interactively');\n  } else throw err;\n}","preventionTips":["Always pass --project in CI; never rely on name matching with --yes","Keep package.json `name` aligned with the intended project name","Use unique project names per service in shared orgs","Document the project id/slug in your deploy configuration"],"tags":["configuration","deploy","ambiguity","cli"],"backgroundTag":"ambiguous-target-requires-flag","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}