From 6ac2f09a531aeef19ca1389aca7fb2fc2dfb61e0 Mon Sep 17 00:00:00 2001 From: Sonarly Claude Code Date: Sat, 7 Mar 2026 15:11:38 +0000 Subject: [PATCH] chore: improve monitoring for FK violation during calendar event association INS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **Problem**: Commit `d4303469ff5` replaced all PostgreSQL error messages with the generic string `"Data validation error."` in `computeTwentyORMException`. This made it impossible to distinguish between different types of database errors (FK violations, check violations, not-null violations, etc.) in Sentry alerts and logs. The error code is the only diagnostic signal, but it was only stored in the `PostgresException.code` property — not visible in the error message that appears in Sentry. **Fix**: Changed the generic message from `"Data validation error."` to `"Data validation error (code: ${errorCode})."` which includes the specific PostgreSQL error code (e.g., `23503` for FK violations, `23505` for unique violations). This preserves the sanitization intent (no SQL, table names, or column names are exposed) while providing enough diagnostic information to identify the specific database constraint that was violated. For example, the Sentry error will now show `"Unknown error ... : Data validation error (code: 23503)."` instead of the uninformative `"Data validation error."`. --- .../error-handling/compute-twenty-orm-exception.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/twenty-server/src/engine/twenty-orm/error-handling/compute-twenty-orm-exception.ts b/packages/twenty-server/src/engine/twenty-orm/error-handling/compute-twenty-orm-exception.ts index f9fad80e6b1..69fe8c410fe 100644 --- a/packages/twenty-server/src/engine/twenty-orm/error-handling/compute-twenty-orm-exception.ts +++ b/packages/twenty-server/src/engine/twenty-orm/error-handling/compute-twenty-orm-exception.ts @@ -62,7 +62,10 @@ export const computeTwentyORMException = async ( isDefined(errorCode) && Object.values(POSTGRESQL_ERROR_CODES).includes(errorCode) ) { - throw new PostgresException('Data validation error.', errorCode); + throw new PostgresException( + `Data validation error (code: ${errorCode}).`, + errorCode, + ); } throw error; }