-
Notifications
You must be signed in to change notification settings - Fork 141
fix(rum-core): capture stack trace from syntax errors properly #1239
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
Conversation
📦 Bundlesize report
|
🌐 Coverage report
|
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.
LGTM!
return true | ||
} | ||
|
||
export function createStackTraces(stackParser, errorEvent) { |
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.
Is it correct that we are now passing stackParser here in order to mock this library when testing? :)
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.
yes, that's right! 🎉 . In this particular scenario the option of injecting the dependency was the simplest strategy for making the testing experience smooth.
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.
Any reason why you didnt go with mocking error-stack-parser
using spy instead?
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.
Unfortunately, with jasmine we cannot spy properly a third-party (node_modules one) dependency. Not with our project setup at least 😢
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.
LGTM 🎉 Good catch Alberto.
Context
The RUM agent was capturing errors thrown in inline scripts with an empty stack trace. There is a nuance to highlight, though.
This only affects to errors whose type is SyntaxError and have been triggered because of a malformed JavaScript code. This tend to occur when the browser is parsing the document.
The following two examples will help to understand that nuance:
Example 1 (KO): SyntaxError because of malformed JavaScript while parsing the document:
As we can see on the screenshot below the stacktrace was empty:
Example 2 (OK): SyntaxError because of bad usage of JSON.parse
As we can see on the screenshot below the stack trace was not empty, since this kind of SyntaxError was being handled properly:
How are we generating stacktraces?
One of the steps of the error capturing flow is the one that generates the stacktrace from an error event. Given the complexity that some cases have (cross browsing support for instance) we rely on a third-party library named error-stack-parser. Unfortunately, that case is not being handled as expected.
Fix
The ErrorEvent that the browser dispatches when an uncaught error takes place contains all the information we need to generate the stacktrace. So, that's what we do now, we create a stack trace of a single element which contains the missing information.
After the fix, the stacktrace of example 1 looks this way: 🎉
Next
We are going to create an issue in the third-party library to report the unexpected behaviour.Edit: issue created stacktracejs/error-stack-parser#81