Skip to content

The open alternative to Salesforce, designed for AI.

fix(workflow): stop reporting user-facing step errors to Sentry (#26041)

Charles Bochet4862252f5545
diff --git a/packages/twenty-server/src/modules/workflow/workflow-executor/utils/__tests__/is-user-facing-workflow-executor-error.util.spec.ts b/packages/twenty-server/src/modules/workflow/workflow-executor/utils/__tests__/is-user-facing-workflow-executor-error.util.spec.ts
new file mode 100644
index 00000000000..79b195060ef
--- /dev/null
+++ b/packages/twenty-server/src/modules/workflow/workflow-executor/utils/__tests__/is-user-facing-workflow-executor-error.util.spec.ts
@@ -0,0 +1,74 @@
+import {
+ BillingException,
+ BillingExceptionCode,
+} from 'src/engine/core-modules/billing/billing.exception';
+import {
+ UsageLimitException,
+ UsageLimitExceptionCode,
+} from 'src/engine/core-modules/usage-limit/exceptions/usage-limit.exception';
+import {
+ WorkflowStepExecutorException,
+ WorkflowStepExecutorExceptionCode,
+} from 'src/modules/workflow/workflow-executor/exceptions/workflow-step-executor.exception';
+import { isUserFacingWorkflowExecutorError } from 'src/modules/workflow/workflow-executor/utils/is-user-facing-workflow-executor-error.util';
+
+describe('isUserFacingWorkflowExecutorError', () => {
+ it('returns true for exhausted billing credits', () => {
+ const error = new BillingException(
+ 'Credits exhausted',
+ BillingExceptionCode.BILLING_CREDITS_EXHAUSTED,
+ );
+
+ expect(isUserFacingWorkflowExecutorError(error)).toBe(true);
+ });
+
+ it('returns true for an inactive subscription', () => {
+ const error = new BillingException(
+ 'No active subscription',
+ BillingExceptionCode.BILLING_SUBSCRIPTION_INACTIVE,
+ );
+
+ expect(isUserFacingWorkflowExecutorError(error)).toBe(true);
+ });
+
+ it('returns true for an exhausted usage quota', () => {
+ const error = new UsageLimitException(
+ 'Quota exhausted',
+ UsageLimitExceptionCode.QUOTA_EXHAUSTED,
+ );
+
+ expect(isUserFacingWorkflowExecutorError(error)).toBe(true);
+ });
+
+ it('returns false for a platform-state billing error the user cannot resolve', () => {
+ const error = new BillingException(
+ 'Subscription not found',
+ BillingExceptionCode.BILLING_SUBSCRIPTION_NOT_FOUND,
+ );
+
+ expect(isUserFacingWorkflowExecutorError(error)).toBe(false);
+ });
+
+ it.each([
+ WorkflowStepExecutorExceptionCode.INVALID_STEP_TYPE,
+ WorkflowStepExecutorExceptionCode.INVALID_STEP_INPUT,
+ WorkflowStepExecutorExceptionCode.STEP_NOT_FOUND,
+ ])('returns true for user-facing workflow step executor code %s', (code) => {
+ const error = new WorkflowStepExecutorException('User error', code);
+
+ expect(isUserFacingWorkflowExecutorError(error)).toBe(true);
+ });
+
+ it('returns false for internal workflow step executor errors', () => {
+ const error = new WorkflowStepExecutorException(
+ 'Internal error',
+ WorkflowStepExecutorExceptionCode.INTERNAL_ERROR,
+ );
+
+ expect(isUserFacingWorkflowExecutorError(error)).toBe(false);
+ });
+
+ it('returns false for a plain error', () => {
+ expect(isUserFacingWorkflowExecutorError(new Error('boom'))).toBe(false);
+ });
+});
diff --git a/packages/twenty-server/src/modules/workflow/workflow-executor/utils/is-user-facing-workflow-executor-error.util.ts b/packages/twenty-server/src/modules/workflow/workflow-executor/utils/is-user-facing-workflow-executor-error.util.ts
new file mode 100644
index 00000000000..6470b16b864
--- /dev/null
+++ b/packages/twenty-server/src/modules/workflow/workflow-executor/utils/is-user-facing-workflow-executor-error.util.ts
@@ -0,0 +1,43 @@
+import {
+ BillingException,
+ BillingExceptionCode,
+} from 'src/engine/core-modules/billing/billing.exception';
+import {
+ UsageLimitException,
+ UsageLimitExceptionCode,
+} from 'src/engine/core-modules/usage-limit/exceptions/usage-limit.exception';
+import {
+ WorkflowStepExecutorException,
+ WorkflowStepExecutorExceptionCode,
+} from 'src/modules/workflow/workflow-executor/exceptions/workflow-step-executor.exception';
+
+const USER_FACING_STEP_EXECUTOR_EXCEPTION_CODES = [
+ WorkflowStepExecutorExceptionCode.INVALID_STEP_TYPE,
+ WorkflowStepExecutorExceptionCode.INVALID_STEP_INPUT,
+ WorkflowStepExecutorExceptionCode.STEP_NOT_FOUND,
+];
+
+const USER_FACING_BILLING_EXCEPTION_CODES = [
+ BillingExceptionCode.BILLING_CREDITS_EXHAUSTED,
+ BillingExceptionCode.BILLING_SUBSCRIPTION_INACTIVE,
+];
+
+const USER_FACING_USAGE_LIMIT_EXCEPTION_CODES = [
+ UsageLimitExceptionCode.QUOTA_EXHAUSTED,
+];
+
+export const isUserFacingWorkflowExecutorError = (error: unknown): boolean => {
+ if (error instanceof WorkflowStepExecutorException) {
+ return USER_FACING_STEP_EXECUTOR_EXCEPTION_CODES.includes(error.code);
+ }
+
+ if (error instanceof BillingException) {
+ return USER_FACING_BILLING_EXCEPTION_CODES.includes(error.code);
+ }
+
+ if (error instanceof UsageLimitException) {
+ return USER_FACING_USAGE_LIMIT_EXCEPTION_CODES.includes(error.code);
+ }
+
+ return false;
+};
diff --git a/packages/twenty-server/src/modules/workflow/workflow-executor/workspace-services/workflow-executor.workspace-service.ts b/packages/twenty-server/src/modules/workflow/workflow-executor/workspace-services/workflow-executor.workspace-service.ts
index 2e973948376..814d181c149 100644
--- a/packages/twenty-server/src/modules/workflow/workflow-executor/workspace-services/workflow-executor.workspace-service.ts
+++ b/packages/twenty-server/src/modules/workflow/workflow-executor/workspace-services/workflow-executor.workspace-service.ts
@@ -19,12 +19,9 @@ import { UsageOperationType } from 'src/engine/core-modules/usage/enums/usage-op
import { UsageResourceType } from 'src/engine/core-modules/usage/enums/usage-resource-type.enum';
import { UsageUnit } from 'src/engine/core-modules/usage/enums/usage-unit.enum';
import { UsageRecorderService } from 'src/engine/core-modules/usage/services/usage-recorder.service';
+import { shouldCaptureException } from 'src/engine/utils/global-exception-handler.util';
import { WorkflowRunStatus } from 'src/modules/workflow/common/standard-objects/workflow-run.workspace-entity';
import { workflowHasRunningSteps } from 'src/modules/workflow/common/utils/workflow-has-running-steps.util';
-import {
- WorkflowStepExecutorException,
- WorkflowStepExecutorExceptionCode,
-} from 'src/modules/workflow/workflow-executor/exceptions/workflow-step-executor.exception';
import { WorkflowActionFactory } from 'src/modules/workflow/workflow-executor/factories/workflow-action.factory';
import { type WorkflowActionOutput } from 'src/modules/workflow/workflow-executor/types/workflow-action-output.type';
import {
@@ -33,6 +30,7 @@ import {
} from 'src/modules/workflow/workflow-executor/types/workflow-executor-input';
import { getStepRetryAttempt } from 'src/modules/workflow/workflow-executor/utils/get-step-retry-attempt.util';
import { getStepRetryDelayMs } from 'src/modules/workflow/workflow-executor/utils/get-step-retry-delay-ms.util';
+import { isUserFacingWorkflowExecutorError } from 'src/modules/workflow/workflow-executor/utils/is-user-facing-workflow-executor-error.util';
import { stepHasRetryAttemptsLeft } from 'src/modules/workflow/workflow-executor/utils/step-has-retry-attempts-left.util';
import { shouldExecuteStep } from 'src/modules/workflow/workflow-executor/utils/should-execute-step.util';
import { shouldFailSafely } from 'src/modules/workflow/workflow-executor/utils/should-fail-safely.util';
@@ -475,13 +473,9 @@ export class WorkflowExecutorWorkspaceService {
},
});
} catch (error) {
- const isUserError =
- error instanceof WorkflowStepExecutorException &&
- (error.code === WorkflowStepExecutorExceptionCode.INVALID_STEP_TYPE ||
- error.code === WorkflowStepExecutorExceptionCode.INVALID_STEP_INPUT ||
- error.code === WorkflowStepExecutorExceptionCode.STEP_NOT_FOUND);
+ const isUserError = isUserFacingWorkflowExecutorError(error);
- if (!isUserError) {
+ if (!isUserError && shouldCaptureException(error)) {
this.exceptionHandlerService.captureExceptions([error], {
workspace: { id: workspaceId },
});