Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): Explicitly report external hook failures #12830

Merged
merged 1 commit into from
Jan 27, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion packages/cli/src/external-hooks.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -20,6 +21,7 @@ export class ExternalHooks {
private dbCollections: IExternalHooksFunctions['dbCollections'];

constructor(
private readonly errorReporter: ErrorReporter,
userRepository: UserRepository,
settingsRepository: SettingsRepository,
credentialsRepository: CredentialsRepository,
Expand Down Expand Up @@ -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 });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. We could use ensureError to prevent the lint exception.
  2. We could add 'external-hooks' to tags for filtering.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Does this linting rule even provide any value here? cause being unknown is perfectly acceptable here.
  2. We can use the error message for filtering

Copy link
Contributor

@ivov ivov Jan 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. True, mostly noise.
  2. My thinking was that it'd be more useful to have the actual error message in the Sentry event title rather than External hook "${hookName}" failed which can apply to lots of disparate errors, especially as every hook is an array of callbacks. The won't be grouped because of the cause will be different, but still messy as we're mostly interested in the cause.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. I'm hoping that this won't happen frequently enough, and we'll fix external hook as soon as possible. if that happens, we shouldn't need to worry about grouping 🤞🏽

this.errorReporter.error(error, { level: 'fatal' });
throw error;
}
}
}

Expand Down
Loading