refactor(core): Emit different error for issue in execution or trigger

This commit is contained in:
Jan Oberhauser 2022-06-07 15:43:47 +02:00
parent 59a59e0c5f
commit b36c290d78
3 changed files with 45 additions and 17 deletions

View file

@ -591,13 +591,20 @@ export interface ITransferNodeTypes {
} }
export interface IWorkflowErrorData { export interface IWorkflowErrorData {
[key: string]: IDataObject | string | number | ExecutionError; // eslint-disable-next-line @typescript-eslint/no-explicit-any
execution: { [key: string]: any;
execution?: {
id?: string; id?: string;
url?: string;
retryOf?: string;
error: ExecutionError; error: ExecutionError;
lastNodeExecuted: string; lastNodeExecuted: string;
mode: WorkflowExecuteMode; mode: WorkflowExecuteMode;
}; };
trigger?: {
error: ExecutionError;
mode: WorkflowExecuteMode;
};
workflow: { workflow: {
id?: string; id?: string;
name: string; name: string;

View file

@ -64,6 +64,7 @@ import {
getWorkflowOwner, getWorkflowOwner,
} from './UserManagement/UserManagementHelper'; } from './UserManagement/UserManagementHelper';
import { whereClause } from './WorkflowHelpers'; import { whereClause } from './WorkflowHelpers';
import { IWorkflowErrorData } from './Interfaces';
const ERROR_TRIGGER_TYPE = config.getEnv('nodes.errorTriggerType'); const ERROR_TRIGGER_TYPE = config.getEnv('nodes.errorTriggerType');
@ -91,20 +92,37 @@ export function executeErrorWorkflow(
} }
if (fullRunData.data.resultData.error !== undefined) { if (fullRunData.data.resultData.error !== undefined) {
const workflowErrorData = { let workflowErrorData: IWorkflowErrorData;
execution: {
id: executionId, if (executionId) {
url: pastExecutionUrl, // The error did happen in an execution
error: fullRunData.data.resultData.error, workflowErrorData = {
lastNodeExecuted: fullRunData.data.resultData.lastNodeExecuted!, execution: {
mode, id: executionId,
retryOf, url: pastExecutionUrl,
}, error: fullRunData.data.resultData.error,
workflow: { lastNodeExecuted: fullRunData.data.resultData.lastNodeExecuted!,
id: workflowData.id !== undefined ? workflowData.id.toString() : undefined, mode,
name: workflowData.name, 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 // 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. // 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.

View file

@ -10,7 +10,10 @@ export class WorkflowActivationError extends ExecutionBaseError {
constructor(message: string, error: Error, node?: INode) { constructor(message: string, error: Error, node?: INode) {
super(error); super(error);
this.node = node; this.node = node;
this.cause = error; this.cause = {
message: error.message,
stack: error.stack as string,
};
this.message = message; this.message = message;
} }
} }