Repository navigation
feat: Use framesToPop for InvaliantViolations in React errors #2204
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 |
|---|---|---|
|
|
@@ -870,6 +870,7 @@ TraceKit._computeStackTrace = (function _computeStackTraceWrapper() { | |
| */ | ||
| function computeStackTrace(ex: any, depth: any) { | ||
| var stack = null; | ||
| var popSize = ex && ex.framesToPop; | ||
| depth = depth == null ? 0 : +depth; | ||
|
|
||
| try { | ||
|
|
@@ -878,28 +879,28 @@ TraceKit._computeStackTrace = (function _computeStackTraceWrapper() { | |
| // property first!! | ||
| stack = _computeStackTraceFromStacktraceProp(ex); | ||
| if (stack) { | ||
| return stack; | ||
| return popFrames(stack, popSize); | ||
| } | ||
| } catch (e) {} | ||
|
|
||
| try { | ||
| stack = _computeStackTraceFromStackProp(ex); | ||
| if (stack) { | ||
| return stack; | ||
| return popFrames(stack, popSize); | ||
| } | ||
| } catch (e) {} | ||
|
|
||
| try { | ||
| stack = _computeStackTraceFromOperaMultiLineMessage(ex); | ||
| if (stack) { | ||
| return stack; | ||
| return popFrames(stack, popSize); | ||
| } | ||
| } catch (e) {} | ||
|
|
||
| try { | ||
| stack = _computeStackTraceByWalkingCallerChain(ex, depth + 1); | ||
| if (stack) { | ||
| return stack; | ||
| return popFrames(stack, popSize); | ||
| } | ||
| } catch (e) {} | ||
|
|
||
|
|
@@ -911,6 +912,21 @@ TraceKit._computeStackTrace = (function _computeStackTraceWrapper() { | |
| }; | ||
| } | ||
|
|
||
| function popFrames(stacktrace: any, popSize: number): any { | ||
| if (Number.isNaN(popSize)) { | ||
|
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.
Number.isNaN('sentry'); // false
isNaN('sentry'); // trueBTW,
Contributor
Author
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. @jiananshi I know how they work, thanks for pointing that out anyway :) Yes, 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. Fine, let's take a step back and compare with the previous code: // previous
if (typeof popSize !== 'number' || popSize === 0)
// current
if (Number.isNaN(popSize))In the previous logic you do want a NUMBER but currently anythings besides btw the browser-table is a nice design, just learned that.
Contributor
Author
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. Thankfully it will work just fine anyway, as 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. It's ok, as english is not my mother language previous comment may feel little bit annoying, if it is, pls don't mind.
Contributor
Author
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. It's totally fine, my bad :)
Contributor
Author
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.
Removed (will be commited soon) :) |
||
| return stacktrace; | ||
| } | ||
|
|
||
| try { | ||
| return { | ||
| ...stacktrace, | ||
| stack: stacktrace.stack.slice(popSize), | ||
| }; | ||
| } catch (e) { | ||
| return stacktrace; | ||
| } | ||
| } | ||
|
|
||
| (computeStackTrace as any)._augmentStackTraceWithInitialElement = _augmentStackTraceWithInitialElement; | ||
| (computeStackTrace as any)._computeStackTraceFromStackProp = _computeStackTraceFromStackProp; | ||
|
|
||
|
|
||

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 there a reason not to use default value, then you could remove the number type check?!
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.
It's Tracekit, so we have to be very defensive in here. It's guarding us in case React breaks something, or someone decides to put
framesToPopproperty on their error objects.