Skip to content

Commit

Permalink
fix(repetition-assembler): value to null merge in arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
TatianaFomina committed Oct 26, 2024
1 parent 0cad4d0 commit 9dbdce4
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 4 deletions.
64 changes: 63 additions & 1 deletion cypress/integration/repetitionAssembler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,68 @@ describe('Merging of the repetition and the original event payloads at the overv
expect(result).to.deep.equal(assembledRepetition);
});

it('(array of objects) should replace null in original if the repetition event has value', () => {
originalEvent = {
...originalEvent,
backtrace: [
{
...baseEvent.backtrace[0],
sourceCode: null
}
],
};

repetitionEvent = {
...repetitionEvent,
backtrace: [
{
...baseEvent.backtrace[0],
sourceCode: [
{
content: '111',
line: 4
},
{
content: '222',
line: 5
},
{
content: '333',
line: 6
}
]
}
],
};

assembledRepetition = {
...baseEvent,
backtrace: [
{
...baseEvent.backtrace[0],
sourceCode: [
{
content: '111',
line: 4
},
{
content: '222',
line: 5
},
{
content: '333',
line: 6
}
]
}
],
};

const result = repetitionAssembler(originalEvent, repetitionEvent);

expect(result).to.deep.equal(assembledRepetition);
});

it('should take the repetition field value instead of the original event value in the array of objects', () => {
originalEvent = {
...originalEvent,
Expand Down Expand Up @@ -229,4 +291,4 @@ describe('Merging of the repetition and the original event payloads at the overv

expect(result).to.deep.equal(assembledRepetition);
});
});
});
2 changes: 1 addition & 1 deletion src/types/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ export interface HawkEventBacktraceFrame {
/**
* Part of source code file near the called line
*/
sourceCode: BacktraceSourceCode[];
sourceCode: BacktraceSourceCode[] | null;

/**
* Function name extracted from current stack frame
Expand Down
15 changes: 13 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,19 @@ export function repetitionAssembler(originalEvent: HawkEventPayload, repetition:
return originalParam;
}

if (typeof repetitionParam === 'object' && typeof originalEvent === 'object') {
return repetitionAssembler(originalParam, repetitionParam);

if (typeof repetitionParam === 'object' && typeof originalParam === 'object') {
/**
* If original event has null but repetition has some value, we need to return repetition value
*/
if (originalParam === null) {
return repetitionParam;
/**
* Otherwise, we need to recursively merge original and repetition values
*/
} else {
return repetitionAssembler(originalParam, repetitionParam);
}
}

return repetitionParam;
Expand Down

0 comments on commit 9dbdce4

Please sign in to comment.