Skip to content

Commit c465e93

Browse files
author
Jimmy
committed
Initialise empty exceptions array
Fixes unshift undefined error which can occur when two identical errors are sent consecutively. Issue described here #448
1 parent 0124e92 commit c465e93

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

packages/core/lib/segments/attributes/subsegment.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ Subsegment.prototype.addError = function addError(err, remote) {
191191
if (this.segment && this.segment.exception) {
192192
if (err === this.segment.exception.ex) {
193193
this.fault = true;
194-
this.cause = { id: this.segment.exception.cause };
194+
this.cause = { id: this.segment.exception.cause, exceptions: [] };
195195
return;
196196
}
197197
delete this.segment.exception;

packages/core/test/unit/segments/attributes/subsegment.test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,13 @@ describe('Subsegment', function() {
137137
subsegment.addError(err, true);
138138
exceptionStub.should.have.been.calledWithExactly(err, true);
139139
});
140+
it('should initialise exceptions if matching errors are passed consecutively', function () {
141+
subsegment.segment = { trace_id: '1-58c835af-cf6bfe9f8f2c5b84a6d1f50c', parent_id: '12345abc3456def' };
142+
subsegment.addError(err);
143+
subsegment.addError(err);
144+
assert.equal(subsegment.cause.exceptions.length, 0);
145+
assert.notEqual(subsegment.cause.exceptions, undefined);
146+
});
140147
});
141148

142149
describe('#incrementCounter', function() {

0 commit comments

Comments
 (0)