refactor(core): Switch plain errors in core to ApplicationError (no-changelog) (#7873)

Ensure all errors in `core` are `ApplicationError` or children of it and
contain no variables in the message, to continue normalizing all the
errors we report to Sentry

Follow-up to: https://github.com/n8n-io/n8n/pull/7857
This commit is contained in:
Iván Ovejero
2023-11-30 09:06:19 +01:00
committed by GitHub
parent cd474f1562
commit b16dd21909
10 changed files with 135 additions and 101 deletions

View File

@@ -84,9 +84,7 @@ describe('Credentials', () => {
credentials.getData('base.otherNode');
expect(true).toBe(false);
} catch (e) {
expect(e.message).toBe(
'The node of type "base.otherNode" does not have access to credentials "testName" of type "testType".',
);
expect(e.message).toBe('Node does not have access to credential');
}
// Get the data which will be saved in database

View File

@@ -1,5 +1,5 @@
import type { IRun, WorkflowTestData } from 'n8n-workflow';
import { createDeferredPromise, Workflow } from 'n8n-workflow';
import { ApplicationError, createDeferredPromise, Workflow } from 'n8n-workflow';
import { WorkflowExecute } from '@/WorkflowExecute';
import * as Helpers from './helpers';
@@ -45,7 +45,7 @@ describe('WorkflowExecute', () => {
// Check if the output data of the nodes is correct
for (const nodeName of Object.keys(testData.output.nodeData)) {
if (result.data.resultData.runData[nodeName] === undefined) {
throw new Error(`Data for node "${nodeName}" is missing!`);
throw new ApplicationError('Data for node is missing', { extra: { nodeName } });
}
const resultData = result.data.resultData.runData[nodeName].map((nodeData) => {
@@ -108,7 +108,7 @@ describe('WorkflowExecute', () => {
// Check if the output data of the nodes is correct
for (const nodeName of Object.keys(testData.output.nodeData)) {
if (result.data.resultData.runData[nodeName] === undefined) {
throw new Error(`Data for node "${nodeName}" is missing!`);
throw new ApplicationError('Data for node is missing', { extra: { nodeName } });
}
const resultData = result.data.resultData.runData[nodeName].map((nodeData) => {
@@ -172,7 +172,7 @@ describe('WorkflowExecute', () => {
// Check if the output data of the nodes is correct
for (const nodeName of Object.keys(testData.output.nodeData)) {
if (result.data.resultData.runData[nodeName] === undefined) {
throw new Error(`Data for node "${nodeName}" is missing!`);
throw new ApplicationError('Data for node is missing', { extra: { nodeName } });
}
const resultData = result.data.resultData.runData[nodeName].map((nodeData) => {

View File

@@ -24,7 +24,7 @@ import type {
INodeTypeData,
} from 'n8n-workflow';
import { ICredentialsHelper, NodeHelpers, WorkflowHooks } from 'n8n-workflow';
import { ApplicationError, ICredentialsHelper, NodeHelpers, WorkflowHooks } from 'n8n-workflow';
import { Credentials } from '@/Credentials';
import { predefinedNodesTypes } from './constants';
@@ -177,11 +177,11 @@ export function getNodeTypes(testData: WorkflowTestData[] | WorkflowTestData) {
for (const nodeName of nodeNames) {
if (!nodeName.startsWith('n8n-nodes-base.')) {
throw new Error(`Unknown node type: ${nodeName}`);
throw new ApplicationError('Unknown node type', { tags: { nodeType: nodeName } });
}
const loadInfo = knownNodes[nodeName.replace('n8n-nodes-base.', '')];
if (!loadInfo) {
throw new Error(`Unknown node type: ${nodeName}`);
throw new ApplicationError('Unknown node type', { tags: { nodeType: nodeName } });
}
const sourcePath = loadInfo.sourcePath.replace(/^dist\//, './').replace(/\.js$/, '.ts');
const nodeSourcePath = path.join(BASE_DIR, 'nodes-base', sourcePath);
@@ -218,7 +218,7 @@ export const workflowToTests = (dirname: string, testFolder = 'workflows') => {
const description = filePath.replace('.json', '');
const workflowData = readJsonFileSync<IWorkflowBase>(filePath);
if (workflowData.pinData === undefined) {
throw new Error('Workflow data does not contain pinData');
throw new ApplicationError('Workflow data does not contain pinData');
}
const nodeData = preparePinData(workflowData.pinData);