chore: improve monitoring for FK violation during calendar event association INS

**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."`.
This commit is contained in:
Sonarly Claude Code
2026-03-07 15:11:38 +00:00
parent 5843d1d4cd
commit 6ac2f09a53
@@ -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;
}