diff --git a/packages/nodes-base/nodes/Transform/Summarize/Summarize.node.ts b/packages/nodes-base/nodes/Transform/Summarize/Summarize.node.ts index 83ded6d7af..f8c1d99f27 100644 --- a/packages/nodes-base/nodes/Transform/Summarize/Summarize.node.ts +++ b/packages/nodes-base/nodes/Transform/Summarize/Summarize.node.ts @@ -32,6 +32,17 @@ export class Summarize implements INodeType { }, inputs: [NodeConnectionType.Main], outputs: [NodeConnectionType.Main], + // [ria] + hints: [ + { + message: + "The field '$aggregation.field' does not exist in any items. Consider turning on 'Continue if Field Not Found' in options.", + displayCondition: '={{ $parameter["fieldsToSummarize"] }}', + whenToDisplay: 'afterExecution', + location: 'outputPane', + }, + ], + // [ria] properties: [ { displayName: 'Fields to Summarize', @@ -315,16 +326,17 @@ 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); + // try { + const fieldNotFound = checkIfFieldExists.call(this, newItems, fieldsToSummarize, getValue); + // if this call returns something (the not-found field name) + // make it return something instead of throwing an error + // } catch (error) { + if (options.continueIfFieldNotFound || fieldNotFound) { + const itemData = generatePairedItemData(items.length); - return [[{ json: {}, pairedItem: itemData }]]; - } else { - throw error; - } + return [[{ json: {}, pairedItem: itemData }]]; + } else { + // throw error; // show hints instead } } diff --git a/packages/nodes-base/nodes/Transform/Summarize/utils.ts b/packages/nodes-base/nodes/Transform/Summarize/utils.ts index 0094d4d8ef..03afa04118 100644 --- a/packages/nodes-base/nodes/Transform/Summarize/utils.ts +++ b/packages/nodes-base/nodes/Transform/Summarize/utils.ts @@ -1,10 +1,5 @@ import get from 'lodash/get'; -import { - type IDataObject, - type GenericValue, - type IExecuteFunctions, - NodeOperationError, -} from 'n8n-workflow'; +import { type IDataObject, type GenericValue, type IExecuteFunctions } from 'n8n-workflow'; type AggregationType = | 'append' @@ -94,6 +89,7 @@ export const fieldValueGetter = (disableDotNotation?: boolean) => { }; export function checkIfFieldExists( + // add tests that check that no error is thrown and instead warning is issued this: IExecuteFunctions, items: IDataObject[], aggregations: Aggregations, @@ -105,10 +101,13 @@ export function checkIfFieldExists( } const exist = items.some((item) => getValue(item, aggregation.field) !== undefined); if (!exist) { - throw new NodeOperationError( - this.getNode(), - `The field '${aggregation.field}' does not exist in any items`, - ); + return aggregation.field; + // throw new NodeOperationError( + // turn this into warning instead of error will return early + // return aggregation.field -> field name can be used in the hint description! but if it returns... does it end the iteration!? + // this.getNode(), + // `The field '${aggregation.field}' does not exist in any items`, + // ); } } }