Skip to content
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

Merged
merged 28 commits into from
Oct 3, 2022
Merged

Conversation

liywjl
Copy link
Contributor

@liywjl liywjl commented Sep 16, 2022

Motivation

We want to support the Error.cause property when it is present

Changes

  • use formatUnknownError and processError to add causes to the RawError object
  • use flattenErrorCauses to flattern nested error causes
  • update tests and fixtures

Testing

  • Local
  • Staging
  • Unit
  • End to end

I have gone over the contributing documentation.

@liywjl liywjl requested a review from a team as a code owner September 16, 2022 14:24
@codecov-commenter
Copy link

codecov-commenter commented Sep 16, 2022

Codecov Report

Merging #1740 (3536ec1) into main (e1322e1) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           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     
Impacted Files Coverage Δ
packages/rum-core/test/fixtures.ts 100.00% <ø> (ø)
...ackages/core/src/domain/error/trackRuntimeError.ts 100.00% <100.00%> (ø)
packages/core/src/tools/error.ts 93.87% <100.00%> (+3.25%) ⬆️
...omain/rumEventsCollection/error/errorCollection.ts 68.18% <100.00%> (-2.66%) ⬇️
packages/core/src/tools/timeUtils.ts 97.43% <0.00%> (-2.57%) ⬇️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

packages/core/src/tools/error.ts Outdated Show resolved Hide resolved
packages/core/src/tools/error.spec.ts Outdated Show resolved Hide resolved
packages/core/src/tools/error.spec.ts Outdated Show resolved Hide resolved
packages/core/src/tools/error.ts Outdated Show resolved Hide resolved
packages/core/src/tools/error.ts Outdated Show resolved Hide resolved
packages/core/src/tools/error.ts Outdated Show resolved Hide resolved
packages/core/src/tools/error.ts Outdated Show resolved Hide resolved
packages/rum-core/src/rawRumEvent.types.ts Outdated Show resolved Hide resolved
packages/rum-core/src/rawRumEvent.types.ts Outdated Show resolved Hide resolved
packages/core/src/tools/error.ts Outdated Show resolved Hide resolved
packages/core/src/tools/error.ts Outdated Show resolved Hide resolved
packages/core/src/tools/error.spec.ts Outdated Show resolved Hide resolved
Comment on lines +168 to +170
it('should only return the first 10 errors if nested chain is longer', () => {
const error = new Error('foo') as ErrorWithCause
error.cause = error
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one!

packages/core/src/tools/error.ts Outdated Show resolved Hide resolved
packages/core/src/tools/error.ts Outdated Show resolved Hide resolved
packages/core/src/tools/error.ts Outdated Show resolved Hide resolved
packages/core/src/tools/error.ts Show resolved Hide resolved
packages/core/src/tools/error.ts Outdated Show resolved Hide resolved
packages/core/src/tools/error.ts Outdated Show resolved Hide resolved
packages/core/src/tools/error.spec.ts Outdated Show resolved Hide resolved
packages/core/src/tools/error.spec.ts Outdated Show resolved Hide resolved
packages/core/src/tools/error.spec.ts Outdated Show resolved Hide resolved
packages/core/src/tools/error.spec.ts Outdated Show resolved Hide resolved
packages/core/src/tools/error.ts Outdated Show resolved Hide resolved
packages/core/src/tools/error.spec.ts Outdated Show resolved Hide resolved
packages/core/src/tools/error.spec.ts Outdated Show resolved Hide resolved
packages/core/src/tools/error.spec.ts Outdated Show resolved Hide resolved
Comment on lines 138 to 166
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')
Copy link
Contributor

@bcaudan bcaudan Sep 23, 2022

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?

Copy link
Contributor Author

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

Copy link
Contributor

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?

@liywjl liywjl changed the title [RUMF-1353] Add Error.cause property ✨ [RUMF-1353] Add Error.cause property Sep 23, 2022
@liywjl liywjl merged commit 050491e into main Oct 3, 2022
@liywjl liywjl deleted the william/error-cause-property branch October 3, 2022 09:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants