mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 01:56:46 +00:00
feat(Summarize Node): Turns error when field not found in items into warning (#11889)
Co-authored-by: Dana Lee <dana@n8n.io> Co-authored-by: Elias Meire <elias@meire.dev>
This commit is contained in:
@@ -5,6 +5,8 @@ import {
|
||||
type INodeExecutionData,
|
||||
type INodeType,
|
||||
type INodeTypeDescription,
|
||||
NodeExecutionOutput,
|
||||
type NodeExecutionHint,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import {
|
||||
@@ -16,7 +18,6 @@ import {
|
||||
fieldValueGetter,
|
||||
splitData,
|
||||
} from './utils';
|
||||
import { generatePairedItemData } from '../../../utils/utilities';
|
||||
|
||||
export class Summarize implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
@@ -25,7 +26,7 @@ export class Summarize implements INodeType {
|
||||
icon: 'file:summarize.svg',
|
||||
group: ['transform'],
|
||||
subtitle: '',
|
||||
version: 1,
|
||||
version: [1, 1.1],
|
||||
description: 'Sum, count, max, etc. across items',
|
||||
defaults: {
|
||||
name: 'Summarize',
|
||||
@@ -248,7 +249,12 @@ export class Summarize implements INodeType {
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
description:
|
||||
"Whether to continue if field to summarize can't be found in any items and return single empty item, owerwise an error would be thrown",
|
||||
"Whether to continue if field to summarize can't be found in any items and return single empty item, otherwise an error would be thrown",
|
||||
displayOptions: {
|
||||
hide: {
|
||||
'@version': [{ _cnd: { gte: 1.1 } }],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Disable Dot Notation',
|
||||
@@ -314,20 +320,6 @@ export class Summarize implements INodeType {
|
||||
|
||||
const nodeVersion = this.getNode().typeVersion;
|
||||
|
||||
if (nodeVersion < 2.1) {
|
||||
try {
|
||||
checkIfFieldExists.call(this, newItems, fieldsToSummarize, getValue);
|
||||
} catch (error) {
|
||||
if (options.continueIfFieldNotFound) {
|
||||
const itemData = generatePairedItemData(items.length);
|
||||
|
||||
return [[{ json: {}, pairedItem: itemData }]];
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const aggregationResult = splitData(
|
||||
fieldsToSplitBy,
|
||||
newItems,
|
||||
@@ -336,6 +328,21 @@ export class Summarize implements INodeType {
|
||||
getValue,
|
||||
);
|
||||
|
||||
const fieldsNotFound: NodeExecutionHint[] = [];
|
||||
try {
|
||||
checkIfFieldExists.call(this, newItems, fieldsToSummarize, getValue);
|
||||
} catch (error) {
|
||||
if (nodeVersion > 1 || options.continueIfFieldNotFound) {
|
||||
const fieldNotFoundHint: NodeExecutionHint = {
|
||||
message: error instanceof Error ? error.message : String(error),
|
||||
location: 'outputPane',
|
||||
};
|
||||
fieldsNotFound.push(fieldNotFoundHint);
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
if (options.outputFormat === 'singleItem') {
|
||||
const executionData: INodeExecutionData = {
|
||||
json: aggregationResult,
|
||||
@@ -343,7 +350,7 @@ export class Summarize implements INodeType {
|
||||
item: index,
|
||||
})),
|
||||
};
|
||||
return [[executionData]];
|
||||
return new NodeExecutionOutput([[executionData]], fieldsNotFound);
|
||||
} else {
|
||||
if (!fieldsToSplitBy.length) {
|
||||
const { pairedItems, ...json } = aggregationResult;
|
||||
@@ -353,7 +360,7 @@ export class Summarize implements INodeType {
|
||||
item: index,
|
||||
})),
|
||||
};
|
||||
return [[executionData]];
|
||||
return new NodeExecutionOutput([[executionData]], fieldsNotFound);
|
||||
}
|
||||
const returnData = aggregationToArray(aggregationResult, fieldsToSplitBy);
|
||||
const executionData = returnData.map((item) => {
|
||||
@@ -365,7 +372,7 @@ export class Summarize implements INodeType {
|
||||
})),
|
||||
};
|
||||
});
|
||||
return [executionData];
|
||||
return new NodeExecutionOutput([executionData], fieldsNotFound);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user