Skip to content

Commit 5ce326f

Browse files
committed
ref(core): Simplify linkedErrors mechanism logic
1 parent 891d790 commit 5ce326f

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

packages/core/src/utils/aggregate-errors.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,9 @@ function aggregateExceptionsFromError(
9999
}
100100

101101
function applyExceptionGroupFieldsForParentException(exception: Exception, exceptionId: number): void {
102-
// Don't know if this default makes sense. The protocol requires us to set these values so we pick *some* default.
103-
exception.mechanism = exception.mechanism || { type: 'generic', handled: true };
104-
105102
exception.mechanism = {
103+
handled: true,
104+
type: 'auto.core.linkedErrors',
106105
...exception.mechanism,
107106
...(exception.type === 'AggregateError' && { is_exception_group: true }),
108107
exception_id: exceptionId,
@@ -115,10 +114,8 @@ function applyExceptionGroupFieldsForChildException(
115114
exceptionId: number,
116115
parentId: number | undefined,
117116
): void {
118-
// Don't know if this default makes sense. The protocol requires us to set these values so we pick *some* default.
119-
exception.mechanism = exception.mechanism || { type: 'generic', handled: true };
120-
121117
exception.mechanism = {
118+
handled: true,
122119
...exception.mechanism,
123120
type: 'chained',
124121
source,

packages/core/test/lib/utils/aggregate-errors.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,26 @@ describe('applyAggregateErrorsToEvent()', () => {
160160
expect(event.exception?.values?.[event.exception.values.length - 1]?.mechanism?.type).toBe('instrument');
161161
});
162162

163+
test('should assign a defualt mechanism type for the root exception', () => {
164+
const fakeAggregateError = new FakeAggregateError(
165+
[new Error('Nested Error 1'), new Error('Nested Error 2')],
166+
'Root Error',
167+
);
168+
169+
const exceptionFromError = (_stackParser: StackParser, ex: Error): Exception => {
170+
return { value: ex.message, type: ex.name };
171+
};
172+
173+
const event: Event = { exception: { values: [exceptionFromError(stackParser, fakeAggregateError)] } };
174+
const eventHint: EventHint = { originalException: fakeAggregateError };
175+
176+
applyAggregateErrorsToEvent(exceptionFromError, stackParser, 'cause', 100, event, eventHint);
177+
178+
expect(event.exception?.values?.[event.exception.values.length - 1]?.mechanism?.type).toBe(
179+
'auto.core.linkedErrors',
180+
);
181+
});
182+
163183
test('should recursively walk mixed errors (Aggregate errors and based on `key`)', () => {
164184
const chainedError: ExtendedError = new Error('Nested Error 3');
165185
chainedError.cause = new Error('Nested Error 4');

0 commit comments

Comments
 (0)