{"record":{"id":"ae9bd5b91c647292","repo":"mastra-ai/mastra","slug":"platform-connection-response-missing-database-url","errorCode":null,"errorMessage":"Platform connection response missing DATABASE_URL.","messagePattern":"Platform connection response missing DATABASE_URL\\.","errorType":"exception","errorClass":"PlatformApiError","httpStatus":500,"severity":"error","filePath":"mastracode/mastra-factory/src/create.ts","lineNumber":358,"sourceCode":"      });\n      const ready = await waitForDatabaseReady({\n        token,\n        orgId,\n        projectId: project.id,\n        databaseId: attached.id,\n      });\n      const connection = await getDatabaseConnection({\n        token,\n        orgId,\n        projectId: project.id,\n        databaseId: ready.id,\n      });\n      // `envVars` is an array of `{ name, value, secret }` — Neon rows always\n      // include a single `DATABASE_URL` entry (see services/project-databases\n      // renderConnectionInstructions).\n      const dbEnv = connection.envVars.find(v => v.name === 'DATABASE_URL');\n      if (!dbEnv?.value) {\n        throw new PlatformApiError(500, 'Platform connection response missing DATABASE_URL.');\n      }\n      databaseUrl = dbEnv.value;\n      neonSpinner.stop('Neon database ready.');\n    } catch (err) {\n      neonSpinner.stop('Database provisioning failed.');\n      throw err;\n    }\n    envAccumulator.DATABASE_URL = databaseUrl;\n\n    // 8. Write .env (idempotent — replaces existing keys, appends missing).\n    flush();\n\n    return { orgId, orgName, project, secretKey, databaseUrl };\n  } finally {\n    // Best-effort partial write on failure so a successful `sk_` mint or\n    // project-id isn't thrown away when a later step blows up.\n    flush();\n  }","sourceCodeStart":340,"sourceCodeEnd":376,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/mastracode/mastra-factory/src/create.ts#L340-L376","documentation":"Thrown by runPlatformProvisioning after provisioning a Neon database via the Mastra Platform. The platform connection response's `envVars` array is expected to always contain a `DATABASE_URL` entry with a non-empty value; if it is missing or blank, the provisioning flow cannot proceed and this PlatformApiError (HTTP 500) is thrown so the user gets a clear failure instead of a broken DATABASE_URL downstream.","triggerScenarios":"The Neon connection API call succeeds but returns `connection.envVars` with no entry named 'DATABASE_URL', or the entry's `value` is empty/undefined.","commonSituations":"A platform API contract change where the env var is renamed (e.g. to POOLING_DATABASE_URL or a pooled variant); a partially provisioned database that reports connected but hasn't emitted credentials yet; a mocked/stubbed API response missing the field; a permissions-restricted connection response that redacts secrets.","solutions":["Retry the create-factory run — the provisioning may have been mid-flight and a fresh connection fetch will include DATABASE_URL.","Check the Neon project dashboard and confirm the connection string exists; attach the database manually if needed.","Verify the platform API version the CLI targets matches the server (no renamed env vars); update the CLI or pin a compatible platform version.","If it persists, file/inspect the raw connection response (services/project-databases renderConnectionInstructions) to confirm the contract."],"exampleFix":"// before\nconst dbEnv = connection.envVars.find(v => v.name === 'DATABASE_URL');\nif (!dbEnv?.value) {\n  throw new PlatformApiError(500, 'Platform connection response missing DATABASE_URL.');\n}\n// after\nconst dbEnv = connection.envVars.find(v => v.name === 'DATABASE_URL')\n  ?? connection.envVars.find(v => /DATABASE_URL/i.test(v.name));\nif (!dbEnv?.value) {\n  throw new PlatformApiError(500, `Platform connection response missing DATABASE_URL. Got: ${connection.envVars.map(v => v.name).join(', ') || '(none)'}`);\n}","handlingStrategy":"validation","validationCode":"function hasDatabaseUrl(conn) {\n  return Array.isArray(conn?.envVars) &&\n    conn.envVars.some(v => v?.name === 'DATABASE_URL' && typeof v.value === 'string' && v.value.length > 0);\n}\nif (!hasDatabaseUrl(connection)) throw new Error('Connection response lacks DATABASE_URL; retry provisioning.');","typeGuard":"function hasDbEnv(v) { return typeof v === 'object' && v !== null && v.name === 'DATABASE_URL' && typeof v.value === 'string' && v.value.length > 0; }","tryCatchPattern":"try {\n  databaseUrl = await provisionAndGetDatabaseUrl(opts);\n} catch (err) {\n  if (err instanceof PlatformApiError && err.message.includes('DATABASE_URL')) {\n    console.error('Platform did not return DATABASE_URL. Retry, or attach a DB from the dashboard.');\n  }\n  throw err;\n}","preventionTips":["Pin/verify the CLI and platform API versions so the connection-response contract doesn't drift.","Log envVars names when the response shape is unexpected to ease debugging.","Retry provisioning once automatically before surfacing the error to the user.","Fall back to dashboard-based database attach for repeated failures."],"tags":["platform-api","neon","missing-env-var","contract-violation"],"backgroundTag":"missing-env-var","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}