Skip to content

Comments

fix: Avoid using prisma types on client#23566

Merged
keithwillcode merged 1 commit intomainfrom
fix/prisma_types_being_used_in_fe
Sep 4, 2025
Merged

fix: Avoid using prisma types on client#23566
keithwillcode merged 1 commit intomainfrom
fix/prisma_types_being_used_in_fe

Conversation

@volnei
Copy link
Contributor

@volnei volnei commented Sep 4, 2025

What does this PR do?

Changes the redactError to avoid importing Prisma to client due to barrel export at @calcom/prisma/client. The types itself are not a problem however it requires import of Prisma instance.

@calcom/web:dev: Import traces:
@calcom/web:dev:   #1 [external]:
@calcom/web:dev:     [externals]/@prisma/client [external]
@calcom/web:dev:     ./packages/lib/redactError.ts [Client Component SSR]
@calcom/web:dev:     ./apps/web/app/error.tsx [Client Component SSR]
@calcom/web:dev:     ./apps/web/app/error.tsx [Server Component]
@calcom/web:dev: 
@calcom/web:dev:   #3 [external]:
@calcom/web:dev:     [externals]/@prisma/client [external]
@calcom/web:dev:     ./packages/lib/redactError.ts [Client Component SSR]
@calcom/web:dev:     ./apps/web/app/error.tsx [Client Component SSR]
@calcom/web:dev:     ./apps/web/app/global-error.tsx [Client Component SSR]
@calcom/web:dev:     ./apps/web/app/global-error.tsx [Server Component]

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 4, 2025

Walkthrough

  • Replaced explicit Prisma error class checks with name-based detection: uses error.name matched by case-insensitive regex /Prisma/i.
  • Removed import of Prisma types from "@prisma/client".
  • Updated shouldRedact signature from generic (error: T) to shouldRedact(error: Error).
  • Retained redaction flow: in production, if shouldRedact(error) is true, log and return new Error("An error occurred while querying the database."); otherwise return the original error.
  • No changes to exported/public entity names beyond the shouldRedact parameter type generalization.

Possibly related PRs

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/prisma_types_being_used_in_fe

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

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

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@graphite-app graphite-app bot requested review from a team September 4, 2025 00:30
@keithwillcode keithwillcode added core area: core, team members only foundation labels Sep 4, 2025
@dosubot dosubot bot added the 🐛 bug Something isn't working label Sep 4, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
packages/lib/redactError.ts (2)

7-9: Tighten Prisma detection; avoid false positives and cover more cases.

Anchor the regex and fall back to constructor.name and known P#### codes. This avoids matching e.g. “Prismatic*” and still catches Prisma errors without importing Prisma.

-function shouldRedact(error: Error) {
-  const n = error.name || "";
-  return /Prisma/i.test(n);
-}
+function shouldRedact(error: Error) {
+  const name = error.name ?? (error as any)?.constructor?.name ?? "";
+  if (/^Prisma/i.test(name)) return true;
+  const code = (error as any)?.code;
+  return typeof code === "string" && /^P\d{4}$/.test(code);
+}

16-19: JSON.stringify(Error) yields {}; log structured fields and short‑circuit on prod first.

Current logs drop details; also reorder condition for better DCE. No behavior change.

-  log.debug("Type of Error: ", error.constructor);
-  if (shouldRedact(error) && IS_PRODUCTION) {
-    log.error("Error: ", JSON.stringify(error));
+  log.debug({ msg: "Type of Error", name: error.name, ctor: error.constructor?.name });
+  if (IS_PRODUCTION && shouldRedact(error)) {
+    log.error({ msg: "Prisma error redacted", name: error.name, code: (error as any).code, stack: error.stack });
     return new Error("An error occurred while querying the database.");
   }
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 1209150 and be05d85.

📒 Files selected for processing (1)
  • packages/lib/redactError.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.ts

📄 CodeRabbit inference engine (.cursor/rules/review.mdc)

**/*.ts: For Prisma queries, only select data you need; never use include, always use select
Ensure the credential.key field is never returned from tRPC endpoints or APIs

Files:

  • packages/lib/redactError.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/review.mdc)

Flag excessive Day.js use in performance-critical code; prefer native Date or Day.js .utc() in hot paths like loops

Files:

  • packages/lib/redactError.ts
**/*.{ts,tsx,js,jsx}

⚙️ CodeRabbit configuration file

Flag default exports and encourage named exports. Named exports provide better tree-shaking, easier refactoring, and clearer imports. Exempt main components like pages, layouts, and components that serve as the primary export of a module.

Files:

  • packages/lib/redactError.ts
🧠 Learnings (1)
📓 Common learnings
Learnt from: Udit-takkar
PR: calcom/cal.com#22919
File: packages/features/calAIPhone/providers/retellAI/services/PhoneNumberService.ts:212-220
Timestamp: 2025-08-08T10:26:13.362Z
Learning: In calcom/cal.com PR #22919, packages/features/calAIPhone/providers/retellAI/services/PhoneNumberService.ts should include the phone number in client-facing HttpError messages (e.g., in updatePhoneNumber/getPhoneNumber catch blocks). Do not suggest redacting the phone number from these errors unless requirements change (per maintainer: Udit-takkar).
⏰ Context from checks skipped due to timeout of 180000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Install dependencies / Yarn install & cache
  • GitHub Check: Codacy Static Code Analysis
🔇 Additional comments (2)
packages/lib/redactError.ts (2)

1-6: Good call removing Prisma dependency from this module.

This eliminates the client-bundle pull-in via barrel exports.


1-23: No Prisma imports detected in redactError or FE error boundaries
Validated that packages/lib/redactError.ts and all FE-facing error boundaries (apps/web/app/error.tsx, apps/web/pages/_error.tsx) contain no @prisma/client or @calcom/prisma/client imports.

@keithwillcode keithwillcode enabled auto-merge (squash) September 4, 2025 00:39
@keithwillcode keithwillcode merged commit be7d127 into main Sep 4, 2025
103 of 110 checks passed
@keithwillcode keithwillcode deleted the fix/prisma_types_being_used_in_fe branch September 4, 2025 00:58
@github-actions
Copy link
Contributor

github-actions bot commented Sep 4, 2025

E2E results are ready!

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

Labels

🐛 bug Something isn't working core area: core, team members only foundation ready-for-e2e size/S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants