fix(prisma): throw clear error when DATABASE_URL is missing#29770
fix(prisma): throw clear error when DATABASE_URL is missing#29770prathamesh04 wants to merge 1 commit into
Conversation
Previously, when DATABASE_URL was not set, the Prisma client would attempt to connect with an empty string, resulting in a cryptic connection error. This change adds an early validation that throws a descriptive error message guiding the user to set the environment variable. Closes calcom#24485
|
Welcome to Cal.diy, @prathamesh04! Thanks for opening this pull request. A few things to keep in mind:
A maintainer will review your PR soon. Thanks for contributing! |
📝 WalkthroughWalkthroughPrisma connection string initialization now requires 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/prisma/index.ts`:
- Around line 12-15: Replace the plain Error thrown in the missing
connectionString validation with ErrorWithCode, supplying the repository’s
standard configuration error code while preserving the existing DATABASE_URL
guidance message.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: b8a8f5fa-0a7b-4222-bf89-0f939e0df48c
📒 Files selected for processing (1)
packages/prisma/index.ts
| if (!connectionString) { | ||
| throw new Error( | ||
| "DATABASE_URL environment variable is missing. Please set it in your .env file. Example: DATABASE_URL=\"postgresql://user:password@localhost:5432/calendso\"" | ||
| ); |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win
Use ErrorWithCode for this non-tRPC configuration error.
This file is outside tRPC, so throwing new Error violates the repository error-handling contract. Replace it with ErrorWithCode, including the project’s standard error code, while preserving the guidance message.
As per coding guidelines, use ErrorWithCode for errors in non-tRPC files.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@packages/prisma/index.ts` around lines 12 - 15, Replace the plain Error
thrown in the missing connectionString validation with ErrorWithCode, supplying
the repository’s standard configuration error code while preserving the existing
DATABASE_URL guidance message.
Source: Coding guidelines
What does this PR do?
Adds an early validation in the Prisma client initialization that throws a descriptive error when
DATABASE_URLis not set.Previously, when
DATABASE_URLwas missing, the Prisma client attempted to connect with an empty string, resulting in a cryptic PostgreSQL connection error that was confusing for new contributors and self-hosters.Changes
packages/prisma/index.ts: Replacedprocess.env.DATABASE_URL || ""with an explicit check that throws a clear error message with an example connection string.Before
After
Closes #24485
cc @bandhan-majumder