The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Keep app uninstall hook failures out of Sentry (#28705)
Charles Bochet25b8af256483
diff --git a/packages/twenty-server/src/engine/core-modules/application/application-manifest/services/application-uninstall.service.ts b/packages/twenty-server/src/engine/core-modules/application/application-manifest/services/application-uninstall.service.tsindex 7b619a92f17..71f67d0f77c 100644--- a/packages/twenty-server/src/engine/core-modules/application/application-manifest/services/application-uninstall.service.ts+++ b/packages/twenty-server/src/engine/core-modules/application/application-manifest/services/application-uninstall.service.ts@@ -60,11 +60,20 @@ export class ApplicationUninstallService {for (const application of pendingApplications) {try {- await this.runUninstallHookForWorkspaceDeletion({- application,- workspaceId,- workspaceDeletedAt,- });+ const hookErrorMessage =+ await this.runUninstallHookForWorkspaceDeletion({+ application,+ workspaceId,+ workspaceDeletedAt,+ });++ if (isDefined(hookErrorMessage)) {+ this.logger.warn(+ `workspace-deletion uninstall hook failed: ${application.universalIdentifier}: ${hookErrorMessage}`,+ );+ continue;+ }+await this.applicationRepository.update(workspaceId,{ id: application.id },@@ -161,11 +170,17 @@ export class ApplicationUninstallService {workspaceId: string;}): Promise<void> {try {- await this.runUninstallHook({+ const hookErrorMessage = await this.runUninstallHook({application,workspaceId,payload: { version: application.version ?? undefined },});++ if (isDefined(hookErrorMessage)) {+ this.logger.warn(+ `Uninstall hook failed for application ${application.universalIdentifier}: ${hookErrorMessage}`,+ );+ }} catch (error) {this.logger.warn(`Uninstall hook failed for application ${application.universalIdentifier}: ${error instanceof Error ? error.message : String(error)}`,@@ -181,8 +196,8 @@ export class ApplicationUninstallService {application: ApplicationForUninstallHook;workspaceId: string;workspaceDeletedAt: Date;- }): Promise<void> {- await this.runUninstallHook({+ }): Promise<string | undefined> {+ return this.runUninstallHook({application,workspaceId,workspaceDeletionRequestTimestamp: workspaceDeletedAt.toISOString(),@@ -205,9 +220,9 @@ export class ApplicationUninstallService {workspaceId: string;payload: UninstallHookPayload;workspaceDeletionRequestTimestamp?: string;- }): Promise<void> {+ }): Promise<string | undefined> {if (!isDefined(application.uninstallLogicFunctionId)) {- return;+ return undefined;}this.logger.log(@@ -225,11 +240,6 @@ export class ApplicationUninstallService {: {}),});- if (isDefined(logicFunctionExecutionResult.error)) {- throw new ApplicationException(- logicFunctionExecutionResult.error.errorMessage,- ApplicationExceptionCode.UNINSTALL_ERROR,- );- }+ return logicFunctionExecutionResult.error?.errorMessage;}}diff --git a/packages/twenty-server/test/integration/metadata/suites/application/application-uninstall-retry.integration-spec.ts b/packages/twenty-server/test/integration/metadata/suites/application/application-uninstall-retry.integration-spec.tsindex b00c81c26db..59420520145 100644--- a/packages/twenty-server/test/integration/metadata/suites/application/application-uninstall-retry.integration-spec.ts+++ b/packages/twenty-server/test/integration/metadata/suites/application/application-uninstall-retry.integration-spec.ts@@ -15,6 +15,7 @@ import { type Manifest } from 'twenty-shared/application';import { isDefined } from 'twenty-shared/utils';import { v4 as uuidv4 } from 'uuid';+import { ApplicationExceptionCode } from 'src/engine/core-modules/application/application.exception';import { type ApplicationUninstallService } from 'src/engine/core-modules/application/application-manifest/services/application-uninstall.service';import { type LogicFunctionExecutorService } from 'src/engine/core-modules/logic-function/logic-function-executor/logic-function-executor.service';import { LogicFunctionExecutionStatus } from 'src/engine/metadata-modules/logic-function/dtos/logic-function-execution-result.dto';@@ -197,7 +198,7 @@ describe('Application uninstall retry', () => {await deleteUser({ accessToken: userAccessToken });});- it('records partial progress and retries only the failed hook', async () => {+ it('keeps a failed app hook pending without throwing and retries only that hook', async () => {const workspaceDeletedAt = new Date('2026-08-18T10:00:00.000Z');const applicationUninstallService =getAppProviderByClassName<ApplicationUninstallService>(@@ -224,7 +225,7 @@ describe('Application uninstall retry', () => {workspaceId,workspaceDeletedAt,}),- ).rejects.toThrow('cleanup failed');+ ).resolves.toBeUndefined();expect(executeSpy).toHaveBeenCalledTimes(2);@@ -313,4 +314,28 @@ describe('Application uninstall retry', () => {expect(workspaceIdsWithPendingUninstallHooksAfterRetry.size).toBe(0);}, 120000);++ it('throws on a platform failure but not on an app hook failure', async () => {+ const applicationUninstallService =+ getAppProviderByClassName<ApplicationUninstallService>(+ 'ApplicationUninstallService',+ );++ executeSpy.mockClear();+ executeSpy+ .mockRejectedValueOnce(new Error('executor unavailable'))+ .mockResolvedValueOnce(FAILED_EXECUTION_RESULT);++ const attempt =+ applicationUninstallService.runUninstallHooksForWorkspaceDeletion({+ workspaceId,+ workspaceDeletedAt: new Date('2026-08-19T10:00:00.000Z'),+ });++ await expect(attempt).rejects.toMatchObject({+ code: ApplicationExceptionCode.UNINSTALL_ERROR,+ message: expect.stringContaining('executor unavailable'),+ });+ await expect(attempt).rejects.not.toThrow('cleanup failed');+ }, 120000);});