mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
Ensure all errors in `core` and `workflow` inherit from `ApplicationError` so that we start normalizing all the errors we report to Sentry Follow-up to: https://github.com/n8n-io/n8n/pull/7757#discussion_r1404338844 ### `core` package `ApplicationError` - `FileSystemError` (abstract) - `FileNotFoundError` - `DisallowedFilepathError` - `BinaryDataError` (abstract) - `InvalidModeError` - `InvalidManagerError` - `InvalidExecutionMetadataError` ### `workflow` package `ApplicationError` - `ExecutionBaseError` (abstract) - `WorkflowActivationError` - `WorkflowDeactivationError` - `WebhookTakenError` - `WorkflowOperationError` - `SubworkflowOperationError` - `CliWorkflowOperationError` - `ExpressionError` - `ExpressionExtensionError` - `NodeError` (abstract) - `NodeOperationError` - `NodeApiError` - `NodeSSLError` Up next: - Reorganize errors in `cli` - Flatten the hierarchy in `workflow` (do we really need `ExecutionBaseError`?) - Remove `ExecutionError` type - Stop throwing plain `Error`s - Replace `severity` with `level` - Add node and credential types as `tags` - Add workflow IDs and execution IDs as `extras`
38 lines
1.0 KiB
TypeScript
38 lines
1.0 KiB
TypeScript
import * as Logger from './LoggerProxy';
|
|
import { ApplicationError, type ReportingOptions } from './errors/application.error';
|
|
|
|
interface ErrorReporter {
|
|
report: (error: Error | string, options?: ReportingOptions) => void;
|
|
}
|
|
|
|
const instance: ErrorReporter = {
|
|
report: (error) => {
|
|
if (error instanceof Error) {
|
|
let e = error;
|
|
do {
|
|
const meta = e instanceof ApplicationError ? e.extra : undefined;
|
|
Logger.error(`${e.constructor.name}: ${e.message}`, meta);
|
|
e = e.cause as Error;
|
|
} while (e);
|
|
}
|
|
},
|
|
};
|
|
|
|
export function init(errorReporter: ErrorReporter) {
|
|
instance.report = errorReporter.report;
|
|
}
|
|
|
|
const wrap = (e: unknown) => {
|
|
if (e instanceof Error) return e;
|
|
if (typeof e === 'string') return new Error(e);
|
|
return;
|
|
};
|
|
|
|
export const error = (e: unknown, options?: ReportingOptions) => {
|
|
const toReport = wrap(e);
|
|
if (toReport) instance.report(toReport, options);
|
|
};
|
|
|
|
export const warn = (warning: Error | string, options?: ReportingOptions) =>
|
|
error(warning, { level: 'warning', ...options });
|