-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
fix(core): Classify custom AggregateErrors as exception groups
#19053
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| class CustomAggregateError extends AggregateError { | ||
| constructor(errors, message, options) { | ||
| super(errors, message, options); | ||
| this.name = 'CustomAggregateError'; | ||
| } | ||
| } | ||
|
|
||
| const aggregateError = new CustomAggregateError( | ||
| [new Error('error 1', { cause: new Error('error 1 cause') }), new Error('error 2')], | ||
| 'custom aggregate error', | ||
| { | ||
| cause: new Error('aggregate cause'), | ||
| }, | ||
| ); | ||
|
|
||
| Sentry.captureException(aggregateError); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import { expect } from '@playwright/test'; | ||
| import { sentryTest } from '../../../../utils/fixtures'; | ||
| import { envelopeRequestParser, waitForErrorRequestOnUrl } from '../../../../utils/helpers'; | ||
|
|
||
| sentryTest('captures custom AggregateErrors', async ({ getLocalTestUrl, page }) => { | ||
| const url = await getLocalTestUrl({ testDir: __dirname }); | ||
| const req = await waitForErrorRequestOnUrl(page, url); | ||
| const eventData = envelopeRequestParser(req); | ||
|
|
||
| expect(eventData.exception?.values).toHaveLength(5); // CustomAggregateError + 3 embedded errors + 1 aggregate cause | ||
|
|
||
| // Verify the embedded errors come first | ||
| expect(eventData.exception?.values).toEqual([ | ||
| expect.objectContaining({ | ||
| mechanism: { exception_id: 4, handled: true, parent_id: 0, source: 'errors[1]', type: 'chained' }, | ||
| type: 'Error', | ||
| value: 'error 2', | ||
| }), | ||
| expect.objectContaining({ | ||
| mechanism: { exception_id: 3, handled: true, parent_id: 2, source: 'cause', type: 'chained' }, | ||
| type: 'Error', | ||
| value: 'error 1 cause', | ||
| }), | ||
| expect.objectContaining({ | ||
| mechanism: { exception_id: 2, handled: true, parent_id: 0, source: 'errors[0]', type: 'chained' }, | ||
| type: 'Error', | ||
| value: 'error 1', | ||
| }), | ||
| expect.objectContaining({ | ||
| mechanism: { exception_id: 1, handled: true, parent_id: 0, source: 'cause', type: 'chained' }, | ||
| type: 'Error', | ||
| value: 'aggregate cause', | ||
| }), | ||
| expect.objectContaining({ | ||
| mechanism: { exception_id: 0, handled: true, type: 'generic', is_exception_group: true }, | ||
| type: 'CustomAggregateError', | ||
| value: 'custom aggregate error', | ||
| }), | ||
| ]); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -56,7 +56,7 @@ function aggregateExceptionsFromError( | |
|
|
||
| // Recursively call this function in order to walk down a chain of errors | ||
| if (isInstanceOf(error[key], Error)) { | ||
| applyExceptionGroupFieldsForParentException(exception, exceptionId); | ||
| applyExceptionGroupFieldsForParentException(exception, exceptionId, error); | ||
| const newException = exceptionFromErrorImplementation(parser, error[key] as Error); | ||
| const newExceptionId = newExceptions.length; | ||
| applyExceptionGroupFieldsForChildException(newException, key, newExceptionId, exceptionId); | ||
|
|
@@ -74,10 +74,10 @@ function aggregateExceptionsFromError( | |
|
|
||
| // This will create exception grouping for AggregateErrors | ||
| // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AggregateError | ||
| if (Array.isArray(error.errors)) { | ||
| if (isExceptionGroup(error)) { | ||
| error.errors.forEach((childError, i) => { | ||
| if (isInstanceOf(childError, Error)) { | ||
| applyExceptionGroupFieldsForParentException(exception, exceptionId); | ||
| applyExceptionGroupFieldsForParentException(exception, exceptionId, error); | ||
| const newException = exceptionFromErrorImplementation(parser, childError as Error); | ||
| const newExceptionId = newExceptions.length; | ||
| applyExceptionGroupFieldsForChildException(newException, `errors[${i}]`, newExceptionId, exceptionId); | ||
|
|
@@ -98,12 +98,20 @@ function aggregateExceptionsFromError( | |
| return newExceptions; | ||
| } | ||
|
|
||
| function applyExceptionGroupFieldsForParentException(exception: Exception, exceptionId: number): void { | ||
| function isExceptionGroup(error: ExtendedError): error is ExtendedError & { errors: unknown[] } { | ||
| return Array.isArray(error.errors); | ||
| } | ||
|
|
||
| function applyExceptionGroupFieldsForParentException( | ||
| exception: Exception, | ||
| exceptionId: number, | ||
| error: ExtendedError, | ||
| ): void { | ||
| exception.mechanism = { | ||
| handled: true, | ||
| type: 'auto.core.linked_errors', | ||
| ...(isExceptionGroup(error) && { is_exception_group: true }), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Order change allows mechanism to override
|
||
| ...exception.mechanism, | ||
| ...(exception.type === 'AggregateError' && { is_exception_group: true }), | ||
| exception_id: exceptionId, | ||
| }; | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this test primarily demonstrates that this works for errors with the actual builtin
AggregateErrorclass