From 4c09e9e07447a77a45bab73feb98d156bdbbacdd 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: Wed, 22 Nov 2023 19:12:59 +0100 Subject: [PATCH] handle cancellation properly --- packages/cli/src/ActiveExecutions.ts | 1 + .../repositories/execution.repository.ts | 2 +- packages/core/src/WorkflowExecute.ts | 8 +++- .../editor-ui/src/mixins/pushConnection.ts | 43 ++----------------- 4 files changed, 13 insertions(+), 41 deletions(-) diff --git a/packages/cli/src/ActiveExecutions.ts b/packages/cli/src/ActiveExecutions.ts index 9d606aab7d57dd..3835c02bd29603 100644 --- a/packages/cli/src/ActiveExecutions.ts +++ b/packages/cli/src/ActiveExecutions.ts @@ -177,6 +177,7 @@ export class ActiveExecutions { } else { // Workflow is running in current process this.activeExecutions[executionId].workflowExecution!.cancel(); + setTimeout(() => this.remove(executionId), 10); } return this.getPostExecutePromise(executionId); diff --git a/packages/cli/src/databases/repositories/execution.repository.ts b/packages/cli/src/databases/repositories/execution.repository.ts index df1bb093bc8f36..8b6de66b861d72 100644 --- a/packages/cli/src/databases/repositories/execution.repository.ts +++ b/packages/cli/src/databases/repositories/execution.repository.ts @@ -223,7 +223,7 @@ export class ExecutionRepository extends Repository { async markAsCrashed(executionIds: string[]) { await this.update( - { id: In(executionIds) }, + { id: In(executionIds), status: In(['new', 'running']) }, { status: 'crashed', stoppedAt: new Date(), diff --git a/packages/core/src/WorkflowExecute.ts b/packages/core/src/WorkflowExecute.ts index 42d0c8208c2308..ea67ffb169cfff 100644 --- a/packages/core/src/WorkflowExecute.ts +++ b/packages/core/src/WorkflowExecute.ts @@ -827,8 +827,14 @@ export class WorkflowExecute { onCancel.shouldReject = false; onCancel(() => { - this.abortController.abort(); gotCancel = true; + this.abortController.abort(); + void this.processSuccessExecution( + startedAt, + workflow, + new WorkflowOperationError('Workflow has been canceled!'), + closeFunction, + ); }); const returnPromise = (async () => { diff --git a/packages/editor-ui/src/mixins/pushConnection.ts b/packages/editor-ui/src/mixins/pushConnection.ts index 82cef06ca62f03..717cc4191b9b64 100644 --- a/packages/editor-ui/src/mixins/pushConnection.ts +++ b/packages/editor-ui/src/mixins/pushConnection.ts @@ -19,7 +19,6 @@ import type { IWorkflowBase, SubworkflowOperationError, IExecuteContextData, - NodeOperationError, } from 'n8n-workflow'; import { TelemetryHelpers } from 'n8n-workflow'; @@ -464,55 +463,21 @@ export const pushConnection = defineComponent({ type: 'error', duration: 0, }); - } else if ( - runDataExecuted.data.resultData.error?.name === 'NodeOperationError' && - (runDataExecuted.data.resultData.error as NodeOperationError).functionality === - 'configuration-node' - ) { - // If the error is a configuration error of the node itself doesn't get executed so we can't use lastNodeExecuted for the title + } else { let title: string; - const nodeError = runDataExecuted.data.resultData.error as NodeOperationError; - if (nodeError.node.name) { - title = `Error in sub-node ‘${nodeError.node.name}‘`; + if (runDataExecuted.data.resultData.lastNodeExecuted) { + title = `Problem in node ‘${runDataExecuted.data.resultData.lastNodeExecuted}‘`; } else { title = 'Problem executing workflow'; } this.showMessage({ title, - message: - (nodeError?.description ?? runDataExecutedErrorMessage) + - this.$locale.baseText('pushConnection.executionError.openNode', { - interpolate: { - node: nodeError.node.name, - }, - }), + message: runDataExecutedErrorMessage, type: 'error', duration: 0, dangerouslyUseHTMLString: true, }); - } else { - let title: string; - const isManualExecutionCancelled = - runDataExecutedErrorMessage === 'AbortError' || - (runDataExecuted.mode === 'manual' && runDataExecuted.status === 'canceled'); - - // Do not show the error message if the workflow got canceled manually - if (!isManualExecutionCancelled) { - if (runDataExecuted.data.resultData.lastNodeExecuted) { - title = `Problem in node ‘${runDataExecuted.data.resultData.lastNodeExecuted}‘`; - } else { - title = 'Problem executing workflow'; - } - - this.showMessage({ - title, - message: runDataExecutedErrorMessage, - type: 'error', - duration: 0, - dangerouslyUseHTMLString: true, - }); - } } } else { // Workflow did execute without a problem