Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions packages/core/src/utils/aggregate-errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,9 @@ function aggregateExceptionsFromError(
}

function applyExceptionGroupFieldsForParentException(exception: Exception, exceptionId: number): void {
// Don't know if this default makes sense. The protocol requires us to set these values so we pick *some* default.
exception.mechanism = exception.mechanism || { type: 'generic', handled: true };

exception.mechanism = {
handled: true,
type: 'auto.core.linked_errors',
...exception.mechanism,
...(exception.type === 'AggregateError' && { is_exception_group: true }),
exception_id: exceptionId,
Expand All @@ -115,10 +114,8 @@ function applyExceptionGroupFieldsForChildException(
exceptionId: number,
parentId: number | undefined,
): void {
// Don't know if this default makes sense. The protocol requires us to set these values so we pick *some* default.
exception.mechanism = exception.mechanism || { type: 'generic', handled: true };

exception.mechanism = {
handled: true,
...exception.mechanism,
type: 'chained',
source,
Expand Down
20 changes: 20 additions & 0 deletions packages/core/test/lib/utils/aggregate-errors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,26 @@ describe('applyAggregateErrorsToEvent()', () => {
expect(event.exception?.values?.[event.exception.values.length - 1]?.mechanism?.type).toBe('instrument');
});

test('should assign a defualt mechanism type for the root exception', () => {
const fakeAggregateError = new FakeAggregateError(
[new Error('Nested Error 1'), new Error('Nested Error 2')],
'Root Error',
);

const exceptionFromError = (_stackParser: StackParser, ex: Error): Exception => {
return { value: ex.message, type: ex.name };
};

const event: Event = { exception: { values: [exceptionFromError(stackParser, fakeAggregateError)] } };
const eventHint: EventHint = { originalException: fakeAggregateError };

applyAggregateErrorsToEvent(exceptionFromError, stackParser, 'cause', 100, event, eventHint);

expect(event.exception?.values?.[event.exception.values.length - 1]?.mechanism?.type).toBe(
'auto.core.linked_errors',
);
});

test('should recursively walk mixed errors (Aggregate errors and based on `key`)', () => {
const chainedError: ExtendedError = new Error('Nested Error 3');
chainedError.cause = new Error('Nested Error 4');
Expand Down
Loading