first commit

This commit is contained in:
2025-10-26 23:10:15 +08:00
commit 8f0345b7be
14961 changed files with 2356381 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
import type { Event } from '@sentry/node';
import type { ErrorTags, ErrorLevel, ReportingOptions } from '@n8n/errors';
export type BaseErrorOptions = {
description?: string | undefined | null;
} & ErrorOptions & ReportingOptions;
/**
* Base class for all errors
*/
export declare abstract class BaseError extends Error {
/**
* Error level. Defines which level the error should be logged/reported
* @default 'error'
*/
level: ErrorLevel;
/**
* Whether the error should be reported to Sentry.
* @default true
*/
readonly shouldReport: boolean;
readonly description: string | null | undefined;
readonly tags: ErrorTags;
readonly extra?: Event['extra'];
readonly packageName?: string;
constructor(message: string, { level, description, shouldReport, tags, extra, ...rest }?: BaseErrorOptions);
}
//# sourceMappingURL=base.error.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"base.error.d.ts","sourceRoot":"","sources":["../../../../src/errors/base/base.error.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAG1C,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE3E,MAAM,MAAM,gBAAgB,GAAG;IAAE,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAAA;CAAE,GAAG,YAAY,GACxF,gBAAgB,CAAC;AAClB;;GAEG;AACH,8BAAsB,SAAU,SAAQ,KAAK;IAC5C;;;OAGG;IACH,KAAK,EAAE,UAAU,CAAC;IAElB;;;OAGG;IACH,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC;IAE/B,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IAEhD,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IAEzB,QAAQ,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;IAEhC,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;gBAG7B,OAAO,EAAE,MAAM,EACf,EACC,KAAe,EACf,WAAW,EACX,YAAY,EACZ,IAAS,EACT,KAAK,EACL,GAAG,IAAI,EACP,GAAE,gBAAqB;CAiBzB"}

View File

@@ -0,0 +1,36 @@
import callsites from 'callsites';
/**
* Base class for all errors
*/
export class BaseError extends Error {
/**
* Error level. Defines which level the error should be logged/reported
* @default 'error'
*/
level;
/**
* Whether the error should be reported to Sentry.
* @default true
*/
shouldReport;
description;
tags;
extra;
packageName;
constructor(message, { level = 'error', description, shouldReport, tags = {}, extra, ...rest } = {}) {
super(message, rest);
this.level = level;
this.shouldReport = shouldReport ?? (level === 'error' || level === 'fatal');
this.description = description;
this.tags = tags;
this.extra = extra;
try {
const filePath = callsites()[2].getFileName() ?? '';
const match = /packages\/([^\/]+)\//.exec(filePath)?.[1];
if (match)
this.tags.packageName = match;
}
catch { }
}
}
//# sourceMappingURL=base.error.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"base.error.js","sourceRoot":"","sources":["../../../../src/errors/base/base.error.ts"],"names":[],"mappings":"AACA,OAAO,SAAS,MAAM,WAAW,CAAC;AAMlC;;GAEG;AACH,MAAM,OAAgB,SAAU,SAAQ,KAAK;IAC5C;;;OAGG;IACH,KAAK,CAAa;IAElB;;;OAGG;IACM,YAAY,CAAU;IAEtB,WAAW,CAA4B;IAEvC,IAAI,CAAY;IAEhB,KAAK,CAAkB;IAEvB,WAAW,CAAU;IAE9B,YACC,OAAe,EACf,EACC,KAAK,GAAG,OAAO,EACf,WAAW,EACX,YAAY,EACZ,IAAI,GAAG,EAAE,EACT,KAAK,EACL,GAAG,IAAI,KACc,EAAE;QAExB,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QAErB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,YAAY,GAAG,YAAY,IAAI,CAAC,KAAK,KAAK,OAAO,IAAI,KAAK,KAAK,OAAO,CAAC,CAAC;QAC7E,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QAEnB,IAAI,CAAC;YACJ,MAAM,QAAQ,GAAG,SAAS,EAAE,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,IAAI,EAAE,CAAC;YACpD,MAAM,KAAK,GAAG,sBAAsB,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;YAEzD,IAAI,KAAK;gBAAE,IAAI,CAAC,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;QAC1C,CAAC;QAAC,MAAM,CAAC,CAAA,CAAC;IACX,CAAC;CACD"}

View File

@@ -0,0 +1,16 @@
import type { BaseErrorOptions } from './base.error';
import { BaseError } from './base.error';
export type OperationalErrorOptions = Omit<BaseErrorOptions, 'level'> & {
level?: 'info' | 'warning' | 'error';
};
/**
* Error that indicates a transient issue, like a network request failing,
* a database query timing out, etc. These are expected to happen, are
* transient by nature and should be handled gracefully.
*
* Default level: warning
*/
export declare class OperationalError extends BaseError {
constructor(message: string, opts?: OperationalErrorOptions);
}
//# sourceMappingURL=operational.error.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"operational.error.d.ts","sourceRoot":"","sources":["../../../../src/errors/base/operational.error.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,MAAM,MAAM,uBAAuB,GAAG,IAAI,CAAC,gBAAgB,EAAE,OAAO,CAAC,GAAG;IACvE,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC;CACrC,CAAC;AAEF;;;;;;GAMG;AACH,qBAAa,gBAAiB,SAAQ,SAAS;gBAClC,OAAO,EAAE,MAAM,EAAE,IAAI,GAAE,uBAA4B;CAK/D"}

View File

@@ -0,0 +1,15 @@
import { BaseError } from './base.error';
/**
* Error that indicates a transient issue, like a network request failing,
* a database query timing out, etc. These are expected to happen, are
* transient by nature and should be handled gracefully.
*
* Default level: warning
*/
export class OperationalError extends BaseError {
constructor(message, opts = {}) {
opts.level = opts.level ?? 'warning';
super(message, opts);
}
}
//# sourceMappingURL=operational.error.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"operational.error.js","sourceRoot":"","sources":["../../../../src/errors/base/operational.error.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAMzC;;;;;;GAMG;AACH,MAAM,OAAO,gBAAiB,SAAQ,SAAS;IAC9C,YAAY,OAAe,EAAE,OAAgC,EAAE;QAC9D,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,SAAS,CAAC;QAErC,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IACtB,CAAC;CACD"}

View File

@@ -0,0 +1,16 @@
import type { BaseErrorOptions } from './base.error';
import { BaseError } from './base.error';
export type UnexpectedErrorOptions = Omit<BaseErrorOptions, 'level'> & {
level?: 'error' | 'fatal';
};
/**
* Error that indicates something is wrong in the code: logic mistakes,
* unhandled cases, assertions that fail. These are not recoverable and
* should be brought to developers' attention.
*
* Default level: error
*/
export declare class UnexpectedError extends BaseError {
constructor(message: string, opts?: UnexpectedErrorOptions);
}
//# sourceMappingURL=unexpected.error.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"unexpected.error.d.ts","sourceRoot":"","sources":["../../../../src/errors/base/unexpected.error.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,MAAM,MAAM,sBAAsB,GAAG,IAAI,CAAC,gBAAgB,EAAE,OAAO,CAAC,GAAG;IACtE,KAAK,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC;CAC1B,CAAC;AAEF;;;;;;GAMG;AACH,qBAAa,eAAgB,SAAQ,SAAS;gBACjC,OAAO,EAAE,MAAM,EAAE,IAAI,GAAE,sBAA2B;CAK9D"}

View File

@@ -0,0 +1,15 @@
import { BaseError } from './base.error';
/**
* Error that indicates something is wrong in the code: logic mistakes,
* unhandled cases, assertions that fail. These are not recoverable and
* should be brought to developers' attention.
*
* Default level: error
*/
export class UnexpectedError extends BaseError {
constructor(message, opts = {}) {
opts.level = opts.level ?? 'error';
super(message, opts);
}
}
//# sourceMappingURL=unexpected.error.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"unexpected.error.js","sourceRoot":"","sources":["../../../../src/errors/base/unexpected.error.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAMzC;;;;;;GAMG;AACH,MAAM,OAAO,eAAgB,SAAQ,SAAS;IAC7C,YAAY,OAAe,EAAE,OAA+B,EAAE;QAC7D,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,OAAO,CAAC;QAEnC,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IACtB,CAAC;CACD"}

View File

@@ -0,0 +1,18 @@
import type { BaseErrorOptions } from './base.error';
import { BaseError } from './base.error';
export type UserErrorOptions = Omit<BaseErrorOptions, 'level'> & {
level?: 'info' | 'warning';
description?: string | null | undefined;
};
/**
* Error that indicates the user performed an action that caused an error.
* E.g. provided invalid input, tried to access a resource theyre not
* authorized to, or violates a business rule.
*
* Default level: info
*/
export declare class UserError extends BaseError {
readonly description: string | null | undefined;
constructor(message: string, opts?: UserErrorOptions);
}
//# sourceMappingURL=user.error.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"user.error.d.ts","sourceRoot":"","sources":["../../../../src/errors/base/user.error.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,MAAM,MAAM,gBAAgB,GAAG,IAAI,CAAC,gBAAgB,EAAE,OAAO,CAAC,GAAG;IAChE,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;CACxC,CAAC;AAEF;;;;;;GAMG;AACH,qBAAa,SAAU,SAAQ,SAAS;IACvC,SAAiB,WAAW,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;gBAE5C,OAAO,EAAE,MAAM,EAAE,IAAI,GAAE,gBAAqB;CAKxD"}

View File

@@ -0,0 +1,15 @@
import { BaseError } from './base.error';
/**
* Error that indicates the user performed an action that caused an error.
* E.g. provided invalid input, tried to access a resource theyre not
* authorized to, or violates a business rule.
*
* Default level: info
*/
export class UserError extends BaseError {
constructor(message, opts = {}) {
opts.level = opts.level ?? 'info';
super(message, opts);
}
}
//# sourceMappingURL=user.error.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"user.error.js","sourceRoot":"","sources":["../../../../src/errors/base/user.error.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAOzC;;;;;;GAMG;AACH,MAAM,OAAO,SAAU,SAAQ,SAAS;IAGvC,YAAY,OAAe,EAAE,OAAyB,EAAE;QACvD,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,MAAM,CAAC;QAElC,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IACtB,CAAC;CACD"}