-
Notifications
You must be signed in to change notification settings - Fork 142
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
✨ [RUMF-1353] Add Error.cause property #1740
Conversation
packages/rum-core/src/domain/rumEventsCollection/error/errorCollection.spec.ts
Outdated
Show resolved
Hide resolved
Codecov Report
@@ Coverage Diff @@
## main #1740 +/- ##
=======================================
Coverage 91.03% 91.03%
=======================================
Files 128 128
Lines 4985 4999 +14
Branches 1113 1117 +4
=======================================
+ Hits 4538 4551 +13
- Misses 447 448 +1
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
it('should only return the first 10 errors if nested chain is longer', () => { | ||
const error = new Error('foo') as ErrorWithCause | ||
error.cause = error |
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.
Nice one!
Co-authored-by: Bastien Caudan <bastien.caudan@gmail.com>
packages/rum-core/src/domain/rumEventsCollection/error/errorCollection.ts
Outdated
Show resolved
Hide resolved
error.stack = 'Error: foo: bar\n at <anonymous>:1:15' | ||
|
||
const nestedError = new Error('biz: buz') as ErrorWithCause | ||
nestedError.stack = 'NestedError: biz: buz\n at <anonymous>:2:15' | ||
|
||
const deepNestedError = new Error('fiz: buz') as ErrorWithCause | ||
deepNestedError.stack = 'NestedError: fiz: buz\n at <anonymous>:3:15' | ||
|
||
error.cause = nestedError | ||
nestedError.cause = deepNestedError | ||
|
||
const formatted = computeRawError({ | ||
...DEFAULT_RAW_ERROR_PARMS, | ||
stackTrace: NOT_COMPUTED_STACK_TRACE, | ||
stackTrace, | ||
originalError: error, | ||
handling: ErrorHandling.HANDLED, | ||
source: ErrorSource.SOURCE, | ||
}) | ||
|
||
expect(formatted?.type).toEqual('TypeError') | ||
expect(formatted?.message).toEqual('some typeError message') | ||
expect(formatted.causes?.length).toBe(2) | ||
const causes = formatted.causes as RawErrorCause[] | ||
expect(causes[0].message).toContain(nestedError.message) | ||
expect(causes[0].source).toContain(ErrorSource.SOURCE) | ||
expect(causes[0].type).toEqual('Error') | ||
expect(causes[1].message).toContain(deepNestedError.message) | ||
expect(causes[1].source).toContain(ErrorSource.SOURCE) | ||
expect(causes[1].type).toEqual('Error') |
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.
💬 suggestion: it seems that:
- the input errors stack are not used in the assertions
- except the message, we can't distinguish the two causes
could we improve that?
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.
🤦♂️ just saw that in face we were not actually extracting the stack traces from causes correctly. I have fixed that and updated the tests
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.
Could you ensure that the types are coming from the expected errors as well?
Motivation
We want to support the
Error.cause
property when it is presentChanges
formatUnknownError
andprocessError
to addcauses
to the RawError objectflattenErrorCauses
to flattern nested error causesTesting
I have gone over the contributing documentation.