Skip to content

Commit

Permalink
Skip parsing cause if it is not an Error object
Browse files Browse the repository at this point in the history
  • Loading branch information
angrycat9000 committed Jul 19, 2023
1 parent e56bd39 commit 2ddb344
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
20 changes: 20 additions & 0 deletions spec/core/ExceptionFormatterSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,26 @@ describe('ExceptionFormatter', function() {
.withContext('first root cause stack frame')
.toContain('ExceptionFormatterSpec.js');
});

it('does not throw if cause is a non Error', function() {
const formatter = new jasmineUnderTest.ExceptionFormatter();

expect(function() {
formatter.stack(
new Error('error', {
cause: function() {}
})
);
}).not.toThrowError();

expect(function() {
formatter.stack(
new Error('error', {
cause: 'another error'
})
);
}).not.toThrowError();
});
});
});
});
2 changes: 1 addition & 1 deletion src/core/ExceptionFormatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ getJasmineRequireObj().ExceptionFormatter = function(j$) {
lines.unshift(stackTrace.message);
}

if (error.cause) {
if (error.cause && error.cause instanceof Error) {
const substack = this.stack_(error.cause, {
messageHandling: 'require'
});
Expand Down

0 comments on commit 2ddb344

Please sign in to comment.