Skip to content

Commit

Permalink
feat: Add item information to more node errors (#3681)
Browse files Browse the repository at this point in the history
* ⚡ Add `itemIndex` to node-thrown errors

* ⚡ Add some missing item indexes
  • Loading branch information
ivov committed Jul 12, 2022
1 parent a847190 commit 2a8043c
Show file tree
Hide file tree
Showing 117 changed files with 376 additions and 370 deletions.
3 changes: 3 additions & 0 deletions packages/nodes-base/nodes/ActionNetwork/ActionNetwork.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ export class ActionNetwork implements INodeType {
throw new NodeOperationError(
this.getNode(),
`Please enter at least one field to update for the ${resource}.`,
{ itemIndex: i },
);
}

Expand Down Expand Up @@ -364,6 +365,7 @@ export class ActionNetwork implements INodeType {
throw new NodeOperationError(
this.getNode(),
`Please enter at least one field to update for the ${resource}.`,
{ itemIndex: i },
);
}

Expand Down Expand Up @@ -439,6 +441,7 @@ export class ActionNetwork implements INodeType {
throw new NodeOperationError(
this.getNode(),
`Please enter at least one field to update for the ${resource}.`,
{ itemIndex: i },
);
}

Expand Down
24 changes: 12 additions & 12 deletions packages/nodes-base/nodes/ActiveCampaign/ActiveCampaign.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ export class ActiveCampaign implements INodeType {
addAdditionalFields(body.contact as IDataObject, updateFields);

} else {
throw new NodeOperationError(this.getNode(), `The operation "${operation}" is not known`);
throw new NodeOperationError(this.getNode(), `The operation "${operation}" is not known`, { itemIndex: i });
}
} else if (resource === 'account') {
if (operation === 'create') {
Expand Down Expand Up @@ -515,7 +515,7 @@ export class ActiveCampaign implements INodeType {
addAdditionalFields(body.account as IDataObject, updateFields);

} else {
throw new NodeOperationError(this.getNode(), `The operation "${operation}" is not known`);
throw new NodeOperationError(this.getNode(), `The operation "${operation}" is not known`, { itemIndex: i });
}
} else if (resource === 'accountContact') {
if (operation === 'create') {
Expand Down Expand Up @@ -565,7 +565,7 @@ export class ActiveCampaign implements INodeType {
endpoint = `/api/3/accountContacts/${accountContactId}`;

} else {
throw new NodeOperationError(this.getNode(), `The operation "${operation}" is not known`);
throw new NodeOperationError(this.getNode(), `The operation "${operation}" is not known`, { itemIndex: i });
}
} else if (resource === 'contactTag') {
if (operation === 'add') {
Expand Down Expand Up @@ -595,7 +595,7 @@ export class ActiveCampaign implements INodeType {
endpoint = `/api/3/contactTags/${contactTagId}`;

} else {
throw new NodeOperationError(this.getNode(), `The operation "${operation}" is not known`);
throw new NodeOperationError(this.getNode(), `The operation "${operation}" is not known`, { itemIndex: i });
}
} else if (resource === 'contactList') {
if (operation === 'add') {
Expand Down Expand Up @@ -633,7 +633,7 @@ export class ActiveCampaign implements INodeType {
dataKey = 'contacts';

} else {
throw new NodeOperationError(this.getNode(), `The operation "${operation}" is not known`);
throw new NodeOperationError(this.getNode(), `The operation "${operation}" is not known`, { itemIndex: i });
}
} else if (resource === 'list') {
if (operation === 'getAll') {
Expand Down Expand Up @@ -735,7 +735,7 @@ export class ActiveCampaign implements INodeType {
addAdditionalFields(body.tag as IDataObject, updateFields);

} else {
throw new NodeOperationError(this.getNode(), `The operation "${operation}" is not known`);
throw new NodeOperationError(this.getNode(), `The operation "${operation}" is not known`, { itemIndex: i });
}
} else if (resource === 'deal') {
if (operation === 'create') {
Expand Down Expand Up @@ -854,7 +854,7 @@ export class ActiveCampaign implements INodeType {
endpoint = `/api/3/deals/${dealId}/notes/${dealNoteId}`;

} else {
throw new NodeOperationError(this.getNode(), `The operation "${operation}" is not known`);
throw new NodeOperationError(this.getNode(), `The operation "${operation}" is not known`, { itemIndex: i });
}
} else if (resource === 'connection') {
if (operation === 'create') {
Expand Down Expand Up @@ -929,7 +929,7 @@ export class ActiveCampaign implements INodeType {
endpoint = `/api/3/connections`;

} else {
throw new NodeOperationError(this.getNode(), `The operation "${operation}" is not known`);
throw new NodeOperationError(this.getNode(), `The operation "${operation}" is not known`, { itemIndex: i });
}
} else if (resource === 'ecommerceOrder') {
if (operation === 'create') {
Expand Down Expand Up @@ -1027,7 +1027,7 @@ export class ActiveCampaign implements INodeType {
endpoint = `/api/3/ecomOrders`;

} else {
throw new NodeOperationError(this.getNode(), `The operation "${operation}" is not known`);
throw new NodeOperationError(this.getNode(), `The operation "${operation}" is not known`, { itemIndex: i });
}
} else if (resource === 'ecommerceCustomer') {
if (operation === 'create') {
Expand Down Expand Up @@ -1117,7 +1117,7 @@ export class ActiveCampaign implements INodeType {
endpoint = `/api/3/ecomCustomers`;

} else {
throw new NodeOperationError(this.getNode(), `The operation "${operation}" is not known`);
throw new NodeOperationError(this.getNode(), `The operation "${operation}" is not known`, { itemIndex: i });
}
} else if (resource === 'ecommerceOrderProducts') {
if (operation === 'getByProductId') {
Expand Down Expand Up @@ -1163,11 +1163,11 @@ export class ActiveCampaign implements INodeType {
endpoint = `/api/3/ecomOrderProducts`;

} else {
throw new NodeOperationError(this.getNode(), `The operation "${operation}" is not known`);
throw new NodeOperationError(this.getNode(), `The operation "${operation}" is not known`, { itemIndex: i });
}

} else {
throw new NodeOperationError(this.getNode(), `The resource "${resource}" is not known!`);
throw new NodeOperationError(this.getNode(), `The resource "${resource}" is not known!`, { itemIndex: i });
}

let responseData;
Expand Down
12 changes: 6 additions & 6 deletions packages/nodes-base/nodes/AgileCrm/AgileCrm.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,14 @@ export class AgileCrm implements INodeType {
rules = getFilterRules(conditions, matchType);
Object.assign(filterJson, rules);
} else {
throw new NodeOperationError(this.getNode(), 'At least one condition must be added.');
throw new NodeOperationError(this.getNode(), 'At least one condition must be added.', { itemIndex: i });
}
} else if (filterType === 'json') {
const filterJsonRules = this.getNodeParameter('filterJson', i) as string;
if (validateJSON(filterJsonRules) !== undefined) {
Object.assign(filterJson, JSON.parse(filterJsonRules) as IFilter);
} else {
throw new NodeOperationError(this.getNode(), 'Filter (JSON) must be a valid json');
throw new NodeOperationError(this.getNode(), 'Filter (JSON) must be a valid json', { itemIndex: i });
}
}
body.filterJson = JSON.stringify(filterJson);
Expand Down Expand Up @@ -203,7 +203,7 @@ export class AgileCrm implements INodeType {
Object.assign(body, JSON.parse(additionalFieldsJson));

} else {
throw new NodeOperationError(this.getNode(), 'Additional fields must be a valid JSON');
throw new NodeOperationError(this.getNode(), 'Additional fields must be a valid JSON', { itemIndex: i });
}
}

Expand Down Expand Up @@ -359,7 +359,7 @@ export class AgileCrm implements INodeType {
Object.assign(body, JSON.parse(additionalFieldsJson));

} else {
throw new NodeOperationError(this.getNode(), 'Additional fields must be a valid JSON');
throw new NodeOperationError(this.getNode(), 'Additional fields must be a valid JSON', { itemIndex: i });
}
}
} else {
Expand Down Expand Up @@ -537,7 +537,7 @@ export class AgileCrm implements INodeType {
if (validateJSON(additionalFieldsJson) !== undefined) {
Object.assign(body, JSON.parse(additionalFieldsJson));
} else {
throw new NodeOperationError(this.getNode(), 'Additional fields must be a valid JSON');
throw new NodeOperationError(this.getNode(), 'Additional fields must be a valid JSON', { itemIndex: i });
}
}

Expand Down Expand Up @@ -579,7 +579,7 @@ export class AgileCrm implements INodeType {
Object.assign(body, JSON.parse(additionalFieldsJson));

} else {
throw new NodeOperationError(this.getNode(), 'Additional fields must be valid JSON');
throw new NodeOperationError(this.getNode(), 'Additional fields must be valid JSON', { itemIndex: i });
}
}

Expand Down
6 changes: 3 additions & 3 deletions packages/nodes-base/nodes/ApiTemplateIo/ApiTemplateIo.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ export class ApiTemplateIo implements INodeType {
if (overrideJson !== '') {
const data = validateJSON(overrideJson);
if (data === undefined) {
throw new NodeOperationError(this.getNode(), 'A valid JSON must be provided.');
throw new NodeOperationError(this.getNode(), 'A valid JSON must be provided.', { itemIndex: i });
}
body.overrides = data;
}
Expand Down Expand Up @@ -548,14 +548,14 @@ export class ApiTemplateIo implements INodeType {
if (jsonParameters === false) {
const properties = (this.getNodeParameter('propertiesUi', i) as IDataObject || {}).propertyValues as IDataObject[] || [];
if (properties.length === 0) {
throw new NodeOperationError(this.getNode(), 'The parameter properties cannot be empty');
throw new NodeOperationError(this.getNode(), 'The parameter properties cannot be empty', { itemIndex: i });
}
data = properties.reduce((obj, value) => Object.assign(obj, { [`${value.key}`]: value.value }), {});
} else {
const propertiesJson = this.getNodeParameter('propertiesJson', i) as string;
data = validateJSON(propertiesJson);
if (data === undefined) {
throw new NodeOperationError(this.getNode(), 'A valid JSON must be provided.');
throw new NodeOperationError(this.getNode(), 'A valid JSON must be provided.', { itemIndex: i });
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,11 +460,11 @@ export class AwsRekognition implements INodeType {
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', 0) as string;

if (items[i].binary === undefined) {
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!');
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!', { itemIndex: i });
}

if ((items[i].binary as IBinaryKeyData)[binaryPropertyName] === undefined) {
throw new NodeOperationError(this.getNode(), `No binary data property "${binaryPropertyName}" does not exists on item!`);
throw new NodeOperationError(this.getNode(), `No binary data property "${binaryPropertyName}" does not exists on item!`, { itemIndex: i });
}

const binaryPropertyData = (items[i].binary as IBinaryKeyData)[binaryPropertyName];
Expand Down
4 changes: 2 additions & 2 deletions packages/nodes-base/nodes/Aws/S3/AwsS3.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -598,11 +598,11 @@ export class AwsS3 implements INodeType {
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', 0) as string;

if (items[i].binary === undefined) {
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!');
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!', { itemIndex: i });
}

if ((items[i].binary as IBinaryKeyData)[binaryPropertyName] === undefined) {
throw new NodeOperationError(this.getNode(), `No binary data property "${binaryPropertyName}" does not exists on item!`);
throw new NodeOperationError(this.getNode(), `No binary data property "${binaryPropertyName}" does not exists on item!`, { itemIndex: i });
}

const binaryData = (items[i].binary as IBinaryKeyData)[binaryPropertyName];
Expand Down
4 changes: 2 additions & 2 deletions packages/nodes-base/nodes/Aws/SES/AwsSes.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1121,7 +1121,7 @@ export class AwsSes implements INodeType {
if (toAddresses.length) {
setParameter(params, 'Destination.ToAddresses.member', toAddresses);
} else {
throw new NodeOperationError(this.getNode(), 'At least one "To Address" has to be added!');
throw new NodeOperationError(this.getNode(), 'At least one "To Address" has to be added!', { itemIndex: i });
}

if (additionalFields.configurationSetName) {
Expand Down Expand Up @@ -1174,7 +1174,7 @@ export class AwsSes implements INodeType {
if (toAddresses.length) {
setParameter(params, 'Destination.ToAddresses.member', toAddresses);
} else {
throw new NodeOperationError(this.getNode(), 'At least one "To Address" has to be added!');
throw new NodeOperationError(this.getNode(), 'At least one "To Address" has to be added!', { itemIndex: i });
}

if (additionalFields.configurationSetName) {
Expand Down
4 changes: 2 additions & 2 deletions packages/nodes-base/nodes/Aws/SQS/AwsSqs.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,11 +363,11 @@ export class AwsSqs implements INodeType {
const item = items[i];

if (item.binary === undefined) {
throw new NodeOperationError(this.getNode(), 'No binary data set. So message attribute cannot be added!');
throw new NodeOperationError(this.getNode(), 'No binary data set. So message attribute cannot be added!', { itemIndex: i });
}

if (item.binary[dataPropertyName] === undefined) {
throw new NodeOperationError(this.getNode(), `The binary property "${dataPropertyName}" does not exist. So message attribute cannot be added!`);
throw new NodeOperationError(this.getNode(), `The binary property "${dataPropertyName}" does not exist. So message attribute cannot be added!`, { itemIndex: i });
}

const binaryData = item.binary[dataPropertyName].data;
Expand Down
4 changes: 2 additions & 2 deletions packages/nodes-base/nodes/Aws/Textract/AwsTextract.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,11 @@ export class AwsTextract implements INodeType {
const simple = this.getNodeParameter('simple', i) as boolean;

if (items[i].binary === undefined) {
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!');
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!', { itemIndex: i });
}

if ((items[i].binary as IBinaryKeyData)[binaryProperty] === undefined) {
throw new NodeOperationError(this.getNode(), `No binary data property "${binaryProperty}" does not exists on item!`);
throw new NodeOperationError(this.getNode(), `No binary data property "${binaryProperty}" does not exists on item!`, { itemIndex: i });
}

const binaryPropertyData = (items[i].binary as IBinaryKeyData)[binaryProperty];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ export async function upload(this: IExecuteFunctions, index: number) {
const options = this.getNodeParameter('options', index) as IDataObject;

if (items[index].binary === undefined) {
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!');
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!', { itemIndex: index });
}

const propertyNameUpload = this.getNodeParameter('binaryPropertyName', index) as string;

if (items[index]!.binary![propertyNameUpload] === undefined) {
throw new NodeOperationError(this.getNode(), `No binary data property "${propertyNameUpload}" does not exists on item!`);
throw new NodeOperationError(this.getNode(), `No binary data property "${propertyNameUpload}" does not exists on item!`, { itemIndex: index });
}

const item = items[index].binary as IBinaryKeyData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ export async function upload(this: IExecuteFunctions, index: number) {
const share = this.getNodeParameter('options.share', index, true) as boolean;

if (items[index].binary === undefined) {
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!');
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!', { itemIndex: index });
}

const propertyNameUpload = this.getNodeParameter('binaryPropertyName', index) as string;

if (items[index]!.binary![propertyNameUpload] === undefined) {
throw new NodeOperationError(this.getNode(), `No binary data property "${propertyNameUpload}" does not exists on item!`);
throw new NodeOperationError(this.getNode(), `No binary data property "${propertyNameUpload}" does not exists on item!`, { itemIndex: index });
}

const item = items[index].binary as IBinaryKeyData;
Expand All @@ -55,7 +55,7 @@ export async function upload(this: IExecuteFunctions, index: number) {
};

Object.assign(body.formData, (share) ? { share: 'yes' } : { share: 'no' });

//endpoint
const endpoint = `files`;
const { headers } = await apiRequest.call(this, requestMethod, endpoint, {}, {}, body);
Expand Down
6 changes: 3 additions & 3 deletions packages/nodes-base/nodes/Bitwarden/Bitwarden.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export class Bitwarden implements INodeType {
const updateFields = this.getNodeParameter('updateFields', i) as CollectionUpdateFields;

if (isEmpty(updateFields)) {
throw new NodeOperationError(this.getNode(), `Please enter at least one field to update for the ${resource}.`);
throw new NodeOperationError(this.getNode(), `Please enter at least one field to update for the ${resource}.`, { itemIndex: i });
}

const { groups, externalId } = updateFields;
Expand Down Expand Up @@ -308,7 +308,7 @@ export class Bitwarden implements INodeType {
const updateFields = this.getNodeParameter('updateFields', i) as GroupUpdateFields;

if (isEmpty(updateFields)) {
throw new NodeOperationError(this.getNode(), `Please enter at least one field to update for the ${resource}.`);
throw new NodeOperationError(this.getNode(), `Please enter at least one field to update for the ${resource}.`, { itemIndex: i });
}

// set defaults for `name` and `accessAll`, required by Bitwarden but optional in n8n
Expand Down Expand Up @@ -452,7 +452,7 @@ export class Bitwarden implements INodeType {
const updateFields = this.getNodeParameter('updateFields', i) as MemberUpdateFields;

if (isEmpty(updateFields)) {
throw new NodeOperationError(this.getNode(), `Please enter at least one field to update for the ${resource}.`);
throw new NodeOperationError(this.getNode(), `Please enter at least one field to update for the ${resource}.`, { itemIndex: i });
}

const { accessAll, collections, externalId, type } = updateFields;
Expand Down
6 changes: 3 additions & 3 deletions packages/nodes-base/nodes/Box/Box.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,11 +268,11 @@ export class Box implements INodeType {
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', 0) as string;

if (items[i].binary === undefined) {
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!');
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!', { itemIndex: i });
}
//@ts-ignore
if (items[i].binary[binaryPropertyName] === undefined) {
throw new NodeOperationError(this.getNode(), `No binary data property "${binaryPropertyName}" does not exists on item!`);
throw new NodeOperationError(this.getNode(), `No binary data property "${binaryPropertyName}" does not exists on item!`, { itemIndex: i });
}

const binaryData = (items[i].binary as IBinaryKeyData)[binaryPropertyName];
Expand Down Expand Up @@ -300,7 +300,7 @@ export class Box implements INodeType {
const content = this.getNodeParameter('fileContent', i) as string;

if (fileName === '') {
throw new NodeOperationError(this.getNode(), 'File name must be set!');
throw new NodeOperationError(this.getNode(), 'File name must be set!', { itemIndex: i });
}

attributes['name'] = fileName;
Expand Down
2 changes: 1 addition & 1 deletion packages/nodes-base/nodes/Bubble/Bubble.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export class Bubble implements INodeType {
const filter = options.filtersJson as string;
const data = validateJSON(filter);
if (data === undefined) {
throw new NodeOperationError(this.getNode(), 'Filters must be a valid JSON');
throw new NodeOperationError(this.getNode(), 'Filters must be a valid JSON', { itemIndex: i });
}
qs.constraints = JSON.stringify(data);
}
Expand Down
Loading

0 comments on commit 2a8043c

Please sign in to comment.