Skip to content

Commit d116494

Browse files
DIME-8714: add cause logging test
Co-authored-by: Balint Barki <[email protected]>
1 parent f83fb8e commit d116494

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

src/logger/logger.spec.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,38 @@ describe('Logger', () => {
250250
expect(logArguments.http.response.body.content).to.eql(JSON.stringify(error.response?.data));
251251
});
252252

253+
it('should log causes', () => {
254+
const rootCause = new Error('Root cause error');
255+
rootCause.name = 'RootCauseError';
256+
rootCause.stack = 'RootCauseError: Root cause error\n at rootFunction()';
257+
258+
const intermediateError = new Error('Intermediate error');
259+
intermediateError.name = 'IntermediateError';
260+
intermediateError.stack = 'IntermediateError: Intermediate error\n at intermediateFunction()';
261+
intermediateError.cause = rootCause;
262+
263+
const mainError = new Error('Main error occurred');
264+
mainError.name = 'MainError';
265+
mainError.stack = 'MainError: Main error occurred\n at mainFunction()';
266+
mainError.cause = intermediateError;
267+
268+
logger.fromError('test_action', mainError, { details: 'test details' });
269+
270+
const logArguments = JSON.parse(outputStub.args[0][0]);
271+
expect(logArguments.error.type).to.eql('MainError');
272+
expect(logArguments.error.message).to.eql('Main error occurred');
273+
expect(logArguments.error.cause).to.eql({
274+
type: 'IntermediateError',
275+
message: 'Intermediate error',
276+
stack_trace: intermediateError.stack,
277+
cause: {
278+
type: 'RootCauseError',
279+
message: 'Root cause error',
280+
stack_trace: rootCause.stack,
281+
},
282+
});
283+
});
284+
253285
describe('#customError', () => {
254286
it('should log error as the given severity with action', () => {
255287
const error: Error & { data?: any } = new Error('failed');

0 commit comments

Comments
 (0)