mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
adds comments and first solution attempt
This commit is contained in:
parent
479933fbd5
commit
19a52b9055
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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`,
|
||||
// );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue