Skip to content

fix(prisma): throw clear error when DATABASE_URL is missing#29770

Open
prathamesh04 wants to merge 1 commit into
calcom:mainfrom
prathamesh04:fix/clear-error-missing-database-url
Open

fix(prisma): throw clear error when DATABASE_URL is missing#29770
prathamesh04 wants to merge 1 commit into
calcom:mainfrom
prathamesh04:fix/clear-error-missing-database-url

Conversation

@prathamesh04

Copy link
Copy Markdown

What does this PR do?

Adds an early validation in the Prisma client initialization that throws a descriptive error when DATABASE_URL is not set.

Previously, when DATABASE_URL was 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: Replaced process.env.DATABASE_URL || "" with an explicit check that throws a clear error message with an example connection string.

Before

Error: Error in PostgreSQL connection: error connecting to server: Connection refused

After

Error: DATABASE_URL environment variable is missing. Please set it in your .env file. Example: DATABASE_URL="postgresql://user:password@localhost:5432/calendso"

Closes #24485

cc @bandhan-majumder

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
@github-actions github-actions Bot added api area: API, enterprise API, access token, OAuth 🐛 bug Something isn't working labels Jul 14, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Welcome to Cal.diy, @prathamesh04! Thanks for opening this pull request.

A few things to keep in mind:

  • This is Cal.diy, not Cal.com. Cal.diy is a community-driven, fully open-source fork of Cal.com licensed under MIT. Your changes here will be part of Cal.diy — they will not be deployed to the Cal.com production app.
  • Please review our Contributing Guidelines if you haven't already.
  • Make sure your PR title follows the Conventional Commits format.

A maintainer will review your PR soon. Thanks for contributing!

@prathamesh04 prathamesh04 marked this pull request as ready for review July 14, 2026 03:11
@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Prisma connection string initialization now requires process.env.DATABASE_URL. When the variable is missing, module initialization throws an error with guidance instead of defaulting to an empty string, preventing downstream pool and adapter setup from proceeding with an invalid connection string.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: adding a clear error when DATABASE_URL is missing.
Description check ✅ Passed The description is directly related to the Prisma validation change and the missing DATABASE_URL fix.
Linked Issues check ✅ Passed The change satisfies #24485 by failing early with a descriptive missing-DATABASE_URL error instead of a cryptic crash.
Out of Scope Changes check ✅ Passed No out-of-scope changes are indicated; the patch stays focused on DATABASE_URL validation in Prisma initialization.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between f004349 and 3e955bf.

📒 Files selected for processing (1)
  • packages/prisma/index.ts

Comment thread packages/prisma/index.ts
Comment on lines +12 to +15
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\""
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api area: API, enterprise API, access token, OAuth 🐛 bug Something isn't working size/XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[API] Endpoint /events fails to return data if DATABASE_URL is missing

1 participant