mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 01:56:46 +00:00
refactor(core): Consolidate path-related errors in Sentry (no-changelog) (#7757)
Keep reporting [path-related errors](https://n8nio.sentry.io/issues/4649493725) in Sentry but consolidate them in a single error group. Also, add `options.extra` as `meta` so they remain visible in debug logs: ``` 2023-11-24T11:50:54.852Z | error | ReportableError: Something went wrong "{ test: 123, file: 'LoggerProxy.js', function: 'exports.error' }" ``` --------- Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
This commit is contained in:
@@ -1,11 +1,5 @@
|
||||
import type { Primitives } from './utils';
|
||||
import * as Logger from './LoggerProxy';
|
||||
|
||||
export interface ReportingOptions {
|
||||
level?: 'warning' | 'error' | 'fatal';
|
||||
tags?: Record<string, Primitives>;
|
||||
extra?: Record<string, unknown>;
|
||||
}
|
||||
import { ReportableError, type ReportingOptions } from './errors/reportable.error';
|
||||
|
||||
interface ErrorReporter {
|
||||
report: (error: Error | string, options?: ReportingOptions) => void;
|
||||
@@ -16,7 +10,8 @@ const instance: ErrorReporter = {
|
||||
if (error instanceof Error) {
|
||||
let e = error;
|
||||
do {
|
||||
Logger.error(`${e.constructor.name}: ${e.message}`);
|
||||
const meta = e instanceof ReportableError ? e.extra : undefined;
|
||||
Logger.error(`${e.constructor.name}: ${e.message}`, meta);
|
||||
e = e.cause as Error;
|
||||
} while (e);
|
||||
}
|
||||
|
||||
1
packages/workflow/src/errors/index.ts
Normal file
1
packages/workflow/src/errors/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { ReportableError } from './reportable.error';
|
||||
24
packages/workflow/src/errors/reportable.error.ts
Normal file
24
packages/workflow/src/errors/reportable.error.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import type { Event } from '@sentry/node';
|
||||
|
||||
type Level = 'warning' | 'error' | 'fatal';
|
||||
|
||||
export type ReportingOptions = {
|
||||
level?: Level;
|
||||
} & Pick<Event, 'tags' | 'extra'>;
|
||||
|
||||
export type ReportableErrorOptions = Partial<ErrorOptions> & ReportingOptions;
|
||||
|
||||
export class ReportableError extends Error {
|
||||
readonly level: Level;
|
||||
|
||||
readonly tags?: Event['tags'];
|
||||
|
||||
readonly extra?: Event['extra'];
|
||||
|
||||
constructor(message: string, { level, tags, extra, ...rest }: ReportableErrorOptions) {
|
||||
super(message, rest);
|
||||
this.level = level ?? 'error';
|
||||
this.tags = tags;
|
||||
this.extra = extra;
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import * as NodeHelpers from './NodeHelpers';
|
||||
import * as ObservableObject from './ObservableObject';
|
||||
import * as TelemetryHelpers from './TelemetryHelpers';
|
||||
|
||||
export * from './errors';
|
||||
export * from './Authentication';
|
||||
export * from './Constants';
|
||||
export * from './Cron';
|
||||
|
||||
Reference in New Issue
Block a user