returns warning instead of error when field not found

This commit is contained in:
Ria 2024-11-16 21:28:07 +05:30
parent 19a52b9055
commit 3a1ea55d80

View file

@ -5,6 +5,8 @@ import {
type INodeExecutionData, type INodeExecutionData,
type INodeType, type INodeType,
type INodeTypeDescription, type INodeTypeDescription,
NodeExecutionOutput,
type NodeExecutionHint,
} from 'n8n-workflow'; } from 'n8n-workflow';
import { import {
@ -16,7 +18,7 @@ import {
fieldValueGetter, fieldValueGetter,
splitData, splitData,
} from './utils'; } from './utils';
import { generatePairedItemData } from '../../../utils/utilities'; // import type { IPairedItemData } from '../../../../workflow/src/Interfaces'; // [ria] this is an interface but cannot import it as such!
export class Summarize implements INodeType { export class Summarize implements INodeType {
description: INodeTypeDescription = { description: INodeTypeDescription = {
@ -32,17 +34,6 @@ export class Summarize implements INodeType {
}, },
inputs: [NodeConnectionType.Main], inputs: [NodeConnectionType.Main],
outputs: [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: [ properties: [
{ {
displayName: 'Fields to Summarize', displayName: 'Fields to Summarize',
@ -253,13 +244,14 @@ export class Summarize implements INodeType {
placeholder: 'Add option', placeholder: 'Add option',
default: {}, default: {},
options: [ options: [
// [ria] potentially delete this option??
{ {
displayName: 'Continue if Field Not Found', displayName: 'Continue if Field Not Found',
name: 'continueIfFieldNotFound', name: 'continueIfFieldNotFound',
type: 'boolean', type: 'boolean',
default: false, default: false,
description: 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",
}, },
{ {
displayName: 'Disable Dot Notation', displayName: 'Disable Dot Notation',
@ -326,17 +318,22 @@ export class Summarize implements INodeType {
const nodeVersion = this.getNode().typeVersion; const nodeVersion = this.getNode().typeVersion;
if (nodeVersion < 2.1) { if (nodeVersion < 2.1) {
// try { const fieldNotFound: string | undefined = checkIfFieldExists.call(
const fieldNotFound = checkIfFieldExists.call(this, newItems, fieldsToSummarize, getValue); this,
// if this call returns something (the not-found field name) newItems,
// make it return something instead of throwing an error fieldsToSummarize,
// } catch (error) { getValue,
);
if (options.continueIfFieldNotFound || fieldNotFound) { if (options.continueIfFieldNotFound || fieldNotFound) {
// const itemData: IPairedItemData[] = generatePairedItemData(items.length); // [ria] had to delete type because i was getting compilation errors
const itemData = generatePairedItemData(items.length); const itemData = generatePairedItemData(items.length);
const fieldNotFoundHint: NodeExecutionHint = {
return [[{ json: {}, pairedItem: itemData }]]; message: `The field '${fieldNotFound}' does not exist in any items.`,
location: 'outputPane',
};
return new NodeExecutionOutput([[{ json: {}, pairedItem: itemData }]], [fieldNotFoundHint]);
} else { } else {
// throw error; // show hints instead // throw error; // [ria] show hints instead
} }
} }