Skip to content

Commit

Permalink
fix(core): Prevent NodeErrors from being wrapped multiple times (#8301)
Browse files Browse the repository at this point in the history
  • Loading branch information
netroy committed Jan 16, 2024
1 parent 64ceb16 commit b267bf0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
18 changes: 9 additions & 9 deletions packages/workflow/src/errors/abstract/node.error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ const COMMON_ERRORS: IDataObject = {
* a value recursively inside an error object.
*/
export abstract class NodeError extends ExecutionBaseError {
node: INode;

constructor(node: INode, error: Error | JsonObject) {
if (error instanceof Error) {
super(error.message, { cause: error });
} else {
super('', { errorResponse: error });
}
constructor(
readonly node: INode,
error: Error | JsonObject,
) {
if (error instanceof NodeError) return error;

this.node = node;
const isError = error instanceof Error;
const message = isError ? error.message : '';
const options = isError ? { cause: error } : { errorResponse: error };
super(message, options);
}

/**
Expand Down
16 changes: 16 additions & 0 deletions packages/workflow/test/errors/node.error.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { mock } from 'jest-mock-extended';
import type { INode } from '@/Interfaces';
import { NodeApiError } from '@/errors/node-api.error';
import { NodeOperationError } from '@/errors/node-operation.error';

describe('NodeError', () => {
const node = mock<INode>();

it('should prevent errors from being re-wrapped', () => {
const apiError = new NodeApiError(node, mock({ message: 'Some error happened', code: 500 }));
const opsError = new NodeOperationError(node, mock());

expect(new NodeOperationError(node, apiError)).toEqual(apiError);
expect(new NodeOperationError(node, opsError)).toEqual(opsError);
});
});

0 comments on commit b267bf0

Please sign in to comment.