{"record":{"id":"7f5ab117038f7e18","repo":"mastra-ai/mastra","slug":"failed-to-create-deploy-err-as-detail-stri","errorCode":null,"errorMessage":"Failed to create deploy: ${(err as { detail?: string }).detail || createResp.statusText}","messagePattern":"Failed to create deploy: (.+?)\\)\\.detail \\|\\| createResp\\.statusText\\}","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/cli/src/commands/deploy/index.ts","lineNumber":365,"sourceCode":"  };\n  if (opts.gitBranch) createHeaders['x-git-branch'] = opts.gitBranch;\n  if (opts.mastraVersion) createHeaders['x-mastra-version'] = opts.mastraVersion;\n\n  const createBody: Record<string, unknown> = {};\n  if (opts.envVars) createBody.envVars = opts.envVars;\n  if (opts.disablePlatformObservability !== undefined) {\n    createBody.disablePlatformObservability = opts.disablePlatformObservability;\n  }\n\n  const createResp = await fetch(`${apiUrl}/v1/projects/${projectId}/environments/${environmentId}/deploy`, {\n    method: 'POST',\n    headers: createHeaders,\n    body: JSON.stringify(createBody),\n  });\n\n  if (!createResp.ok) {\n    const err = await createResp.json().catch(() => ({}));\n    throw new Error(`Failed to create deploy: ${(err as { detail?: string }).detail || createResp.statusText}`);\n  }\n\n  const { deploy } = (await createResp.json()) as { deploy: { id: string; uploadUrl: string } };\n\n  // Upload artifact\n  const uploadResp = await fetch(deploy.uploadUrl, {\n    method: 'PUT',\n    headers: {\n      'Content-Type': 'application/zip',\n    },\n    body: zipBuffer,\n  });\n\n  if (!uploadResp.ok) {\n    throw new Error(`Failed to upload artifact: ${uploadResp.statusText}`);\n  }\n\n  // Signal upload complete — uses net-new env-scoped endpoint so the","sourceCodeStart":347,"sourceCodeEnd":383,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/cli/src/commands/deploy/index.ts#L347-L383","documentation":"uploadToEnvironment first POSTs a deploy-creation request to the platform API. If the response is not ok, the CLI parses the JSON body and throws with the server-provided `detail` field, falling back to the HTTP statusText when the body has no detail or isn't JSON. This is the API rejecting deploy creation (auth, validation, limits), surfaced as-is for diagnosis.","triggerScenarios":"The create-deploy POST returns a non-2xx response — e.g., 401/403 auth problems, invalid environmentId/projectId, deploy quota exceeded, or malformed createBody rejected by validation — and the thrown message reflects err.detail or statusText.","commonSituations":"Expired or scoped-out CI token; deploying to an environment id that doesn't exist or belongs to another project; payload exceeding size/limits; API version drift after a CLI or platform upgrade.","solutions":["Read the `detail` in the message — it usually names the exact server-side rejection cause","Verify the token is valid and has deploy permission for projectId/environmentId","Confirm --project and environment identifiers are correct and current","Re-check API compatibility (CLI vs platform version) and upgrade the CLI if the endpoint contract changed"],"exampleFix":"// before\nawait uploadToEnvironment({ environmentId: 'env-old' }); // 404, detail: 'environment not found'\n// after\nawait uploadToEnvironment({ environmentId: 'env-current-id' }); // valid environment","handlingStrategy":"try-catch","validationCode":"// Pre-flight: verify auth and target identifiers before creating the deploy\nif (!token) throw new Error('Missing API token for deploy');\nif (!projectId || !environmentId) throw new Error('projectId and environmentId are required');","typeGuard":"function hasDeployErrorDetail(err: unknown): err is { detail: string } {\n  return typeof err === 'object' && err !== null && typeof (err as { detail?: unknown }).detail === 'string';\n}","tryCatchPattern":"try {\n  const deploy = await uploadToEnvironment(args);\n} catch (err) {\n  if (err instanceof Error && err.message.startsWith('Failed to create deploy:')) {\n    const detail = err.message.slice('Failed to create deploy:'.length).trim();\n    console.error('Server rejected deploy creation:', detail);\n  } else throw err;\n}","preventionTips":["Keep tokens fresh and scoped to the target project/environment","Validate projectId/environmentId before deploying","Check platform status/limits if rejects are quota-shaped (429/413)","Upgrade the CLI after platform API version bumps to stay contract-compatible"],"tags":["http","api","deploy","upload"],"backgroundTag":"deploy-create-rejected","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}