[PR #2510] fix(recipient): filter invalid emails in suggestions #2357

Open
opened 2026-02-26 20:33:32 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/documenso/documenso/pull/2510
Author: @abdulalim110
Created: 2/17/2026
Status: 🔄 Open

Base: mainHead: fix/graceful-recipient-suggestions


📝 Commits (5)

  • a2a518b fix(recipient): filter invalid emails in suggestions
  • 2292182 Merge branch 'main' into fix/graceful-recipient-suggestions
  • 964ca8b Merge branch 'main' into fix/graceful-recipient-suggestions
  • f1916c8 Merge branch 'main' into fix/graceful-recipient-suggestions
  • 9af60a8 Merge branch 'main' into fix/graceful-recipient-suggestions

📊 Changes

1 file changed (+7 additions, -1 deletions)

View changed files

📝 packages/trpc/server/recipient-router/find-recipient-suggestions.ts (+7 -1)

📄 Description

Description

This PR fixes the 500 Internal Server Error caused when findRecipientSuggestions retrieves recipient data with invalid email formats (e.g., empty strings) from the database.

Previously, the strict TRPC output schema (z.string().email()) would throw an error when encountering invalid data, crashing the request. This fix ensures that any invalid email entries are gracefully filtered out before reaching the output validation.

Fixes #2486

Changes Made

  • Added a .filter() method in findRecipientSuggestionsRoute to validate retrieved suggestions.
  • Utilized z.string().email().safeParse() to ensure strict adherence to the output schema.
  • Invalid or empty email strings are now silently removed from the results array instead of causing a server error.

Testing Performed

  • Verified logic locally: Mocked data containing empty strings ("") and invalid email formats are now correctly filtered out, returning only valid objects in the results array.
  • Confirmed that the server no longer throws a TRPC validation error for these cases.

Checklist

  • I have tested these changes locally and they work as expected.
  • I have added/updated tests that prove the effectiveness of these changes.
  • I have updated the documentation to reflect these changes, if applicable.
  • I have followed the project's coding style guidelines.
  • I have addressed the code review feedback from the previous submission, if applicable.

Additional Notes

This approach respects the existing strict Zod schema (z.string().email()) requested by the maintainers, while preventing the application from crashing due to dirty data in the database.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/documenso/documenso/pull/2510 **Author:** [@abdulalim110](https://github.com/abdulalim110) **Created:** 2/17/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/graceful-recipient-suggestions` --- ### 📝 Commits (5) - [`a2a518b`](https://github.com/documenso/documenso/commit/a2a518b2d723e92b7abf2657779be414af805e87) fix(recipient): filter invalid emails in suggestions - [`2292182`](https://github.com/documenso/documenso/commit/22921825205fbf18e4523f54ce9f453acc72a5e8) Merge branch 'main' into fix/graceful-recipient-suggestions - [`964ca8b`](https://github.com/documenso/documenso/commit/964ca8bd0017f812fa39115e88d83707e1ac786c) Merge branch 'main' into fix/graceful-recipient-suggestions - [`f1916c8`](https://github.com/documenso/documenso/commit/f1916c8db3df7a0cc071cc17a82c11eeeac2a1db) Merge branch 'main' into fix/graceful-recipient-suggestions - [`9af60a8`](https://github.com/documenso/documenso/commit/9af60a89d947d892baf4abb2513df47a76146d94) Merge branch 'main' into fix/graceful-recipient-suggestions ### 📊 Changes **1 file changed** (+7 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `packages/trpc/server/recipient-router/find-recipient-suggestions.ts` (+7 -1) </details> ### 📄 Description #### **Description** This PR fixes the `500 Internal Server Error` caused when `findRecipientSuggestions` retrieves recipient data with invalid email formats (e.g., empty strings) from the database. Previously, the strict TRPC output schema (`z.string().email()`) would throw an error when encountering invalid data, crashing the request. This fix ensures that any invalid email entries are gracefully filtered out before reaching the output validation. #### **Related Issue** Fixes #2486 #### **Changes Made** - Added a `.filter()` method in `findRecipientSuggestionsRoute` to validate retrieved suggestions. - Utilized `z.string().email().safeParse()` to ensure strict adherence to the output schema. - Invalid or empty email strings are now silently removed from the `results` array instead of causing a server error. #### **Testing Performed** - Verified logic locally: Mocked data containing empty strings (`""`) and invalid email formats are now correctly filtered out, returning only valid objects in the `results` array. - Confirmed that the server no longer throws a TRPC validation error for these cases. #### **Checklist** * [x] I have tested these changes locally and they work as expected. * [ ] I have added/updated tests that prove the effectiveness of these changes. * [ ] I have updated the documentation to reflect these changes, if applicable. * [x] I have followed the project's coding style guidelines. * [ ] I have addressed the code review feedback from the previous submission, if applicable. #### **Additional Notes** This approach respects the existing strict Zod schema (`z.string().email()`) requested by the maintainers, while preventing the application from crashing due to dirty data in the database. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/documenso#2357
No description provided.