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

[RUM] Catch errors thrown by user callbacks #745

Merged
merged 17 commits into from
Feb 25, 2021
Merged

Conversation

webNeat
Copy link
Contributor

@webNeat webNeat commented Feb 23, 2021

Motivation

Catch errors thrown by user-provided callbacks and log them using console.error.

Changes

  • Added a new tools function catchErrors
  • Used this function to wrap beforeSend, onNewLocation and callbacks given to onReady before the SDK initialization.

Testing

  • unit tests

I have gone over the contributing documentation.

@webNeat webNeat requested a review from a team as a code owner February 23, 2021 16:20
packages/core/src/boot/init.ts Outdated Show resolved Hide resolved
@@ -0,0 +1,11 @@
export function catchErrors<Args extends any[], R>(fn: (...args: Args) => R, errorMsg: string) {
Copy link
Member

Choose a reason for hiding this comment

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

I would rename it to catchUserErrors to make it a bit clearer

packages/core/src/boot/init.ts Outdated Show resolved Hide resolved
packages/core/src/boot/init.ts Outdated Show resolved Hide resolved
Co-authored-by: Benoît <[email protected]>
@codecov-io
Copy link

Codecov Report

Merging #745 (0fc8eca) into master (198f7b8) will decrease coverage by 0.18%.
The diff coverage is 72.72%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #745      +/-   ##
==========================================
- Coverage   82.58%   82.39%   -0.19%     
==========================================
  Files          74       75       +1     
  Lines        3807     3806       -1     
  Branches      907      908       +1     
==========================================
- Hits         3144     3136       -8     
- Misses        663      670       +7     
Impacted Files Coverage Δ
packages/core/src/boot/init.ts 62.85% <0.00%> (-3.81%) ⬇️
packages/core/src/tools/catchErrors.ts 100.00% <100.00%> (ø)
packages/core/src/tools/limitModification.ts 96.42% <100.00%> (-0.35%) ⬇️
.../src/domain/rumEventsCollection/view/trackViews.ts 97.38% <100.00%> (-0.10%) ⬇️
packages/rum-core/src/transport/batch.ts 65.71% <0.00%> (-11.43%) ⬇️
...ckages/core/src/domain/automaticErrorCollection.ts 98.41% <0.00%> (-1.59%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 198f7b8...0fc8eca. Read the comment docs.

packages/core/src/tools/catchUserErrors.ts Outdated Show resolved Hide resolved
packages/core/src/boot/init.spec.ts Outdated Show resolved Hide resolved
packages/core/src/boot/init.spec.ts Show resolved Hide resolved
Co-authored-by: Bastien Caudan <[email protected]>
Copy link
Member

@BenoitZugmeyer BenoitZugmeyer left a comment

Choose a reason for hiding this comment

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

LGTM

webNeat and others added 3 commits February 25, 2021 11:46
This is needed to make the test able to pass its own Lifecycle object
and test that onNewLocation catches user errors after being wrapped.

The stopViewCollection is needed because startViewCollection attaches a
listener to history changes, and if not removed, it will be executed on
all following tests and generates unwanted console.errors
Copy link
Contributor

@bcaudan bcaudan left a comment

Choose a reason for hiding this comment

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

Nice!

@webNeat webNeat merged commit a12910e into master Feb 25, 2021
@webNeat webNeat deleted the amine/wrap-callbacks branch February 25, 2021 13:19
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