fix: Better errors in Switch, If and Filter nodes (#10457)
Some checks failed
Test Master / install-and-build (push) Has been cancelled
Test Master / Unit tests (18.x) (push) Has been cancelled
Test Master / Unit tests (20.x) (push) Has been cancelled
Test Master / Unit tests (22.4) (push) Has been cancelled
Test Master / Lint (push) Has been cancelled
Test Master / Notify Slack on failure (push) Has been cancelled

Co-authored-by: Shireen Missi <shireen@n8n.io>
This commit is contained in:
Michael Kret 2024-08-16 18:36:15 +03:00 committed by GitHub
parent f7fb02e92a
commit aea82cb744
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 53 additions and 16 deletions

View file

@ -1,10 +1,12 @@
import set from 'lodash/set';
import type {
IExecuteFunctions,
INodeExecutionData,
INodeType,
INodeTypeBaseDescription,
INodeTypeDescription,
import {
ApplicationError,
NodeOperationError,
type IExecuteFunctions,
type INodeExecutionData,
type INodeType,
type INodeTypeBaseDescription,
type INodeTypeDescription,
} from 'n8n-workflow';
import { ENABLE_LESS_STRICT_TYPE_VALIDATION } from '../../../utils/constants';
@ -101,7 +103,18 @@ export class FilterV2 implements INodeType {
if (this.continueOnFail(error)) {
discardedItems.push(item);
} else {
throw error;
if (error instanceof NodeOperationError) {
throw error;
}
if (error instanceof ApplicationError) {
set(error, 'context.itemIndex', itemIndex);
throw error;
}
throw new NodeOperationError(this.getNode(), error, {
itemIndex,
});
}
}
});

View file

@ -1,10 +1,12 @@
import set from 'lodash/set';
import type {
IExecuteFunctions,
INodeExecutionData,
INodeType,
INodeTypeBaseDescription,
INodeTypeDescription,
import {
ApplicationError,
NodeOperationError,
type IExecuteFunctions,
type INodeExecutionData,
type INodeType,
type INodeTypeBaseDescription,
type INodeTypeDescription,
} from 'n8n-workflow';
import { ENABLE_LESS_STRICT_TYPE_VALIDATION } from '../../../utils/constants';
@ -101,7 +103,18 @@ export class IfV2 implements INodeType {
if (this.continueOnFail(error)) {
falseItems.push(item);
} else {
throw error;
if (error instanceof NodeOperationError) {
throw error;
}
if (error instanceof ApplicationError) {
set(error, 'context.itemIndex', itemIndex);
throw error;
}
throw new NodeOperationError(this.getNode(), error, {
itemIndex,
});
}
}
});

View file

@ -9,7 +9,7 @@ import type {
INodeTypeBaseDescription,
INodeTypeDescription,
} from 'n8n-workflow';
import { NodeConnectionType, NodeOperationError } from 'n8n-workflow';
import { ApplicationError, NodeConnectionType, NodeOperationError } from 'n8n-workflow';
import set from 'lodash/set';
import { capitalize } from '@utils/utilities';
import { ENABLE_LESS_STRICT_TYPE_VALIDATION } from '../../../utils/constants';
@ -382,7 +382,18 @@ export class SwitchV3 implements INodeType {
returnData[0].push({ json: { error: error.message } });
continue;
}
throw new NodeOperationError(this.getNode(), error);
if (error instanceof NodeOperationError) {
throw error;
}
if (error instanceof ApplicationError) {
set(error, 'context.itemIndex', itemIndex);
throw error;
}
throw new NodeOperationError(this.getNode(), error, {
itemIndex,
});
}
}