Skip to content

Commit

Permalink
fix: Better errors in Switch, If and Filter nodes (n8n-io#10457)
Browse files Browse the repository at this point in the history
Co-authored-by: Shireen Missi <shireen@n8n.io>
  • Loading branch information
michael-radency and ShireenMissi committed Aug 16, 2024
1 parent f7fb02e commit aea82cb
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 16 deletions.
27 changes: 20 additions & 7 deletions packages/nodes-base/nodes/Filter/V2/FilterV2.node.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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,
});
}
}
});
Expand Down
27 changes: 20 additions & 7 deletions packages/nodes-base/nodes/If/V2/IfV2.node.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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,
});
}
}
});
Expand Down
15 changes: 13 additions & 2 deletions packages/nodes-base/nodes/Switch/V3/SwitchV3.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
});
}
}

Expand Down

0 comments on commit aea82cb

Please sign in to comment.