diff --git a/packages/cli/src/Interfaces.ts b/packages/cli/src/Interfaces.ts index 2bc12e638f..74661181ee 100644 --- a/packages/cli/src/Interfaces.ts +++ b/packages/cli/src/Interfaces.ts @@ -591,13 +591,20 @@ export interface ITransferNodeTypes { } export interface IWorkflowErrorData { - [key: string]: IDataObject | string | number | ExecutionError; - execution: { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + [key: string]: any; + execution?: { id?: string; + url?: string; + retryOf?: string; error: ExecutionError; lastNodeExecuted: string; mode: WorkflowExecuteMode; }; + trigger?: { + error: ExecutionError; + mode: WorkflowExecuteMode; + }; workflow: { id?: string; name: string; diff --git a/packages/cli/src/WorkflowExecuteAdditionalData.ts b/packages/cli/src/WorkflowExecuteAdditionalData.ts index 92e4062769..18df0f5f82 100644 --- a/packages/cli/src/WorkflowExecuteAdditionalData.ts +++ b/packages/cli/src/WorkflowExecuteAdditionalData.ts @@ -64,6 +64,7 @@ import { getWorkflowOwner, } from './UserManagement/UserManagementHelper'; import { whereClause } from './WorkflowHelpers'; +import { IWorkflowErrorData } from './Interfaces'; const ERROR_TRIGGER_TYPE = config.getEnv('nodes.errorTriggerType'); @@ -91,20 +92,37 @@ export function executeErrorWorkflow( } if (fullRunData.data.resultData.error !== undefined) { - const workflowErrorData = { - execution: { - id: executionId, - url: pastExecutionUrl, - error: fullRunData.data.resultData.error, - lastNodeExecuted: fullRunData.data.resultData.lastNodeExecuted!, - mode, - retryOf, - }, - workflow: { - id: workflowData.id !== undefined ? workflowData.id.toString() : undefined, - name: workflowData.name, - }, - }; + let workflowErrorData: IWorkflowErrorData; + + if (executionId) { + // The error did happen in an execution + workflowErrorData = { + execution: { + id: executionId, + url: pastExecutionUrl, + error: fullRunData.data.resultData.error, + lastNodeExecuted: fullRunData.data.resultData.lastNodeExecuted!, + mode, + retryOf, + }, + workflow: { + id: workflowData.id !== undefined ? workflowData.id.toString() : undefined, + name: workflowData.name, + }, + }; + } else { + // The error did happen in a trigger + workflowErrorData = { + trigger: { + error: fullRunData.data.resultData.error, + mode, + }, + workflow: { + id: workflowData.id !== undefined ? workflowData.id.toString() : undefined, + name: workflowData.name, + }, + }; + } // Run the error workflow // To avoid an infinite loop do not run the error workflow again if the error-workflow itself failed and it is its own error-workflow. diff --git a/packages/workflow/src/WorkflowActivationError.ts b/packages/workflow/src/WorkflowActivationError.ts index 04b02fc7f2..8c9a2e59af 100644 --- a/packages/workflow/src/WorkflowActivationError.ts +++ b/packages/workflow/src/WorkflowActivationError.ts @@ -10,7 +10,10 @@ export class WorkflowActivationError extends ExecutionBaseError { constructor(message: string, error: Error, node?: INode) { super(error); this.node = node; - this.cause = error; + this.cause = { + message: error.message, + stack: error.stack as string, + }; this.message = message; } }