Skip to content

The open alternative to Salesforce, designed for AI.

fix(exception-handler): guard Sentry driver against non-object exceptions (#25171)

Etienne9a511d976849
diff --git a/packages/twenty-server/src/engine/core-modules/exception-handler/drivers/sentry.driver.ts b/packages/twenty-server/src/engine/core-modules/exception-handler/drivers/sentry.driver.ts
index 969b57cf210..a5b2613770d 100644
--- a/packages/twenty-server/src/engine/core-modules/exception-handler/drivers/sentry.driver.ts
+++ b/packages/twenty-server/src/engine/core-modules/exception-handler/drivers/sentry.driver.ts
@@ -1,4 +1,5 @@
import * as Sentry from '@sentry/node';
+import { isObject } from '@sniptt/guards';
import {
getGenericOperationName,
getHumanReadableNameFromCode,
@@ -48,7 +49,9 @@ export class ExceptionHandlerSentryDriver implements ExceptionHandlerDriverInter
}
for (const exception of exceptions) {
- const errorPath = (exception.path ?? [])
+ const isObjectException = isObject(exception);
+
+ const errorPath = (isObjectException ? (exception.path ?? []) : [])
.map((v: string | number) => (typeof v === 'number' ? '$index' : v))
.join(' > ');
@@ -60,13 +63,13 @@ export class ExceptionHandlerSentryDriver implements ExceptionHandlerDriverInter
});
}
- if ('context' in exception && exception.context) {
+ if (isObjectException && 'context' in exception && exception.context) {
Object.entries(exception.context).forEach(([key, value]) => {
scope.setExtra(key, value);
});
}
- if ('cause' in exception && exception.cause) {
+ if (isObjectException && 'cause' in exception && exception.cause) {
scope.setContext('cause', {
name: exception.cause.name,
message: exception.cause.message,