Skip to content

Commit

Permalink
fix(core): Improve handling of wrapped errors (#8510)
Browse files Browse the repository at this point in the history
  • Loading branch information
netroy authored Jan 31, 2024
1 parent f1910a1 commit 670af16
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
7 changes: 5 additions & 2 deletions packages/workflow/src/errors/abstract/node.error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,15 @@ export abstract class NodeError extends ExecutionBaseError {
readonly node: INode,
error: Error | JsonObject,
) {
if (error instanceof NodeError) return error;

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

if (error instanceof NodeError) {
this.level = 'error';
this.message = `[RE-WRAPPED]: ${message}`;
}
}

/**
Expand Down
14 changes: 10 additions & 4 deletions packages/workflow/test/errors/node.error.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@ import { NodeOperationError } from '@/errors/node-operation.error';
describe('NodeError', () => {
const node = mock<INode>();

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

expect(new NodeOperationError(node, apiError)).toEqual(apiError);
expect(new NodeOperationError(node, opsError)).toEqual(opsError);
expect(wrapped1.level).toEqual('error');
expect(wrapped1.message).toEqual(
'[RE-WRAPPED]: The service was not able to process your request',
);
expect(wrapped2.level).toEqual('error');
expect(wrapped2.message).toEqual('[RE-WRAPPED]: Some operation failed');
});
});

0 comments on commit 670af16

Please sign in to comment.