From a24e4420bb9023f808acd756d125dffaea325968 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=A4=95=E0=A4=BE=E0=A4=B0=E0=A4=A4=E0=A5=8B=E0=A4=AB?= =?UTF-8?q?=E0=A5=8D=E0=A4=AB=E0=A5=87=E0=A4=B2=E0=A4=B8=E0=A5=8D=E0=A4=95?= =?UTF-8?q?=E0=A5=8D=E0=A4=B0=E0=A4=BF=E0=A4=AA=E0=A5=8D=E0=A4=9F=E2=84=A2?= Date: Mon, 27 Jan 2025 10:56:26 +0100 Subject: [PATCH] feat(core): Explicitly report external hook failures (#12830) --- packages/cli/src/external-hooks.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/cli/src/external-hooks.ts b/packages/cli/src/external-hooks.ts index 8a0ba82c985..f6741dd5442 100644 --- a/packages/cli/src/external-hooks.ts +++ b/packages/cli/src/external-hooks.ts @@ -1,5 +1,6 @@ /* eslint-disable @typescript-eslint/no-var-requires */ import { Service } from '@n8n/di'; +import { ErrorReporter } from 'n8n-core'; import { ApplicationError } from 'n8n-workflow'; import config from '@/config'; @@ -20,6 +21,7 @@ export class ExternalHooks { private dbCollections: IExternalHooksFunctions['dbCollections']; constructor( + private readonly errorReporter: ErrorReporter, userRepository: UserRepository, settingsRepository: SettingsRepository, credentialsRepository: CredentialsRepository, @@ -94,7 +96,14 @@ export class ExternalHooks { }; for (const externalHookFunction of this.externalHooks[hookName]) { - await externalHookFunction.apply(externalHookFunctions, hookParameters); + try { + await externalHookFunction.apply(externalHookFunctions, hookParameters); + } catch (cause) { + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + const error = new ApplicationError(`External hook "${hookName}" failed`, { cause }); + this.errorReporter.error(error, { level: 'fatal' }); + throw error; + } } }