-
Notifications
You must be signed in to change notification settings - Fork 16.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move generateFailedExecutionFromError to ExecutionDataService
- Loading branch information
Showing
7 changed files
with
118 additions
and
111 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
packages/cli/src/executions/__tests__/execution-data.service.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { mock } from 'jest-mock-extended'; | ||
import { NodeOperationError } from 'n8n-workflow'; | ||
import type { INode, WorkflowExecuteMode } from 'n8n-workflow'; | ||
|
||
import { ExecutionDataService } from '../execution-data.service'; | ||
|
||
describe('ExecutionDataService', () => { | ||
const service = new ExecutionDataService(); | ||
|
||
describe('generateFailedExecutionFromError', () => { | ||
const mode: WorkflowExecuteMode = 'manual'; | ||
const node = mock<INode>({ name: 'Test Node' }); | ||
const error = new NodeOperationError(node, 'Test error message'); | ||
|
||
it('should generate a failed execution with error details', () => { | ||
const startTime = Date.now(); | ||
|
||
const result = service.generateFailedExecutionFromError(mode, error, node, startTime); | ||
|
||
expect(result.mode).toBe(mode); | ||
expect(result.status).toBe('error'); | ||
expect(result.startedAt).toBeInstanceOf(Date); | ||
expect(result.stoppedAt).toBeInstanceOf(Date); | ||
expect(result.data.resultData.error?.message).toBe(error.message); | ||
|
||
const taskData = result.data.resultData.runData[node.name][0]; | ||
expect(taskData.error?.message).toBe(error.message); | ||
expect(taskData.startTime).toBe(startTime); | ||
expect(taskData.executionStatus).toBe('error'); | ||
expect(result.data.resultData.lastNodeExecuted).toBe(node.name); | ||
expect(result.data.executionData?.nodeExecutionStack[0].node).toEqual(node); | ||
}); | ||
|
||
it('should generate a failed execution without node details if node is undefined', () => { | ||
const result = service.generateFailedExecutionFromError(mode, error, undefined); | ||
|
||
expect(result.mode).toBe(mode); | ||
expect(result.status).toBe('error'); | ||
expect(result.startedAt).toBeInstanceOf(Date); | ||
expect(result.stoppedAt).toBeInstanceOf(Date); | ||
expect(result.data.resultData.error?.message).toBe(error.message); | ||
expect(result.data.resultData.runData).toEqual({}); | ||
expect(result.data.resultData.lastNodeExecuted).toBeUndefined(); | ||
expect(result.data.executionData).toBeUndefined(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { Service } from '@n8n/di'; | ||
import type { ExecutionError, INode, IRun, WorkflowExecuteMode } from 'n8n-workflow'; | ||
|
||
@Service() | ||
export class ExecutionDataService { | ||
generateFailedExecutionFromError( | ||
mode: WorkflowExecuteMode, | ||
error: ExecutionError, | ||
node: INode | undefined, | ||
startTime = Date.now(), | ||
): IRun { | ||
const executionError = { | ||
...error, | ||
message: error.message, | ||
stack: error.stack, | ||
}; | ||
const returnData: IRun = { | ||
data: { | ||
resultData: { | ||
error: executionError, | ||
runData: {}, | ||
}, | ||
}, | ||
finished: false, | ||
mode, | ||
startedAt: new Date(), | ||
stoppedAt: new Date(), | ||
status: 'error', | ||
}; | ||
|
||
if (node) { | ||
returnData.data.startData = { | ||
destinationNode: node.name, | ||
runNodeFilter: [node.name], | ||
}; | ||
returnData.data.resultData.lastNodeExecuted = node.name; | ||
returnData.data.resultData.runData[node.name] = [ | ||
{ | ||
startTime, | ||
executionTime: 0, | ||
executionStatus: 'error', | ||
error: executionError, | ||
source: [], | ||
}, | ||
]; | ||
returnData.data.executionData = { | ||
contextData: {}, | ||
metadata: {}, | ||
waitingExecution: {}, | ||
waitingExecutionSource: {}, | ||
nodeExecutionStack: [ | ||
{ | ||
node, | ||
data: {}, | ||
source: null, | ||
}, | ||
], | ||
}; | ||
} | ||
return returnData; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters