From 231257d0817df711cf900703fd686efb8307eeb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=A4=95=E0=A4=BE=E0=A4=B0=E0=A4=A4=E0=A5=8B=E0=A4=AB?= =?UTF-8?q?=E0=A5=8D=E0=A4=AB=E0=A5=87=E0=A4=B2=E0=A4=B8=E0=A5=8D=E0=A4=95?= =?UTF-8?q?=E0=A5=8D=E0=A4=B0=E0=A4=BF=E0=A4=AA=E0=A5=8D=E0=A4=9F=E2=84=A2?= Date: Fri, 16 Dec 2022 18:47:20 +0100 Subject: [PATCH] fix: Always retain original errors in the error chain on NodeOperationError (#4951) --- .../nodes-base/nodes/FileMaker/FileMaker.node.ts | 12 ++++++------ packages/nodes-base/nodes/Jira/JiraTrigger.node.ts | 2 +- packages/nodes-base/nodes/N8n/GenericFunctions.ts | 4 +++- packages/nodes-base/nodes/NocoDB/NocoDB.node.ts | 10 ++++++++-- .../nodes-base/nodes/SendInBlue/GenericFunctions.ts | 2 +- 5 files changed, 19 insertions(+), 11 deletions(-) diff --git a/packages/nodes-base/nodes/FileMaker/FileMaker.node.ts b/packages/nodes-base/nodes/FileMaker/FileMaker.node.ts index 2c41fdd0ee..63d07febf6 100644 --- a/packages/nodes-base/nodes/FileMaker/FileMaker.node.ts +++ b/packages/nodes-base/nodes/FileMaker/FileMaker.node.ts @@ -604,7 +604,7 @@ export class FileMaker implements INodeType { try { returnData = await layoutsApiRequest.call(this); } catch (error) { - throw new NodeOperationError(this.getNode(), `FileMaker Error: ${error}`); + throw new NodeOperationError(this.getNode(), error); } return returnData; @@ -620,7 +620,7 @@ export class FileMaker implements INodeType { try { layouts = await layoutsApiRequest.call(this); } catch (error) { - throw new NodeOperationError(this.getNode(), `FileMaker Error: ${error}`); + throw new NodeOperationError(this.getNode(), error); } for (const layout of layouts) { returnData.push({ @@ -638,7 +638,7 @@ export class FileMaker implements INodeType { try { fields = await getFields.call(this); } catch (error) { - throw new NodeOperationError(this.getNode(), `FileMaker Error: ${error}`); + throw new NodeOperationError(this.getNode(), error); } for (const field of fields) { returnData.push({ @@ -656,7 +656,7 @@ export class FileMaker implements INodeType { try { scripts = await getScripts.call(this); } catch (error) { - throw new NodeOperationError(this.getNode(), `FileMaker Error: ${error}`); + throw new NodeOperationError(this.getNode(), error); } for (const script of scripts) { if (!script.isFolder) { @@ -676,7 +676,7 @@ export class FileMaker implements INodeType { try { portals = await getPortals.call(this); } catch (error) { - throw new NodeOperationError(this.getNode(), `FileMaker Error: ${error}`); + throw new NodeOperationError(this.getNode(), error); } Object.keys(portals).forEach((portal) => { returnData.push({ @@ -700,7 +700,7 @@ export class FileMaker implements INodeType { try { token = await getToken.call(this); } catch (error) { - throw new NodeOperationError(this.getNode(), `Login fail: ${error}`); + throw new NodeOperationError(this.getNode(), new Error('Login fail', { cause: error })); } let requestOptions: OptionsWithUri; diff --git a/packages/nodes-base/nodes/Jira/JiraTrigger.node.ts b/packages/nodes-base/nodes/Jira/JiraTrigger.node.ts index 0d6341a044..7892f52e32 100644 --- a/packages/nodes-base/nodes/Jira/JiraTrigger.node.ts +++ b/packages/nodes-base/nodes/Jira/JiraTrigger.node.ts @@ -426,7 +426,7 @@ export class JiraTrigger implements INodeType { } catch (e) { throw new NodeOperationError( this.getNode(), - `Could not retrieve HTTP Query Auth credentials: ${e}`, + new Error('Could not retrieve HTTP Query Auth credentials', { cause: e }), ); } if (!httpQueryAuth.name && !httpQueryAuth.value) { diff --git a/packages/nodes-base/nodes/N8n/GenericFunctions.ts b/packages/nodes-base/nodes/N8n/GenericFunctions.ts index 1cedeedc9d..646e96a258 100644 --- a/packages/nodes-base/nodes/N8n/GenericFunctions.ts +++ b/packages/nodes-base/nodes/N8n/GenericFunctions.ts @@ -166,7 +166,9 @@ export const parseAndSetBodyJson = ( } catch (err) { throw new NodeOperationError( this.getNode(), - `The '${parameterName}' property must be valid JSON, but cannot be parsed: ${err}`, + new Error(`The '${parameterName}' property must be valid JSON, but cannot be parsed`, { + cause: err, + }), ); } return requestOptions; diff --git a/packages/nodes-base/nodes/NocoDB/NocoDB.node.ts b/packages/nodes-base/nodes/NocoDB/NocoDB.node.ts index 93a660640a..0cf86a3f38 100644 --- a/packages/nodes-base/nodes/NocoDB/NocoDB.node.ts +++ b/packages/nodes-base/nodes/NocoDB/NocoDB.node.ts @@ -180,7 +180,10 @@ export class NocoDB implements INodeType { const responseData = await apiRequest.call(this, requestMethod, endpoint, {}, {}); return responseData.list.map((i: IDataObject) => ({ name: i.title, value: i.id })); } catch (e) { - throw new NodeOperationError(this.getNode(), `Error while fetching projects! (${e})`); + throw new NodeOperationError( + this.getNode(), + new Error('Error while fetching projects!', { cause: e }), + ); } }, // This only supports using the Project ID @@ -193,7 +196,10 @@ export class NocoDB implements INodeType { const responseData = await apiRequest.call(this, requestMethod, endpoint, {}, {}); return responseData.list.map((i: IDataObject) => ({ name: i.title, value: i.id })); } catch (e) { - throw new NodeOperationError(this.getNode(), `Error while fetching tables! (${e})`); + throw new NodeOperationError( + this.getNode(), + new Error('Error while fetching tables!', { cause: e }), + ); } } else { throw new NodeOperationError(this.getNode(), `No project selected!`); diff --git a/packages/nodes-base/nodes/SendInBlue/GenericFunctions.ts b/packages/nodes-base/nodes/SendInBlue/GenericFunctions.ts index acd8e04cb3..98cfac34b7 100644 --- a/packages/nodes-base/nodes/SendInBlue/GenericFunctions.ts +++ b/packages/nodes-base/nodes/SendInBlue/GenericFunctions.ts @@ -104,7 +104,7 @@ export namespace SendInBlueNode { return requestOptions; } catch (err) { - throw new NodeOperationError(this.getNode(), `${err}`); + throw new NodeOperationError(this.getNode(), err); } }