-
-
Notifications
You must be signed in to change notification settings - Fork 26.8k
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
Improve unmapper file heuristic, add limited warning support, and ignore internal errors #2128
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
afba3fc
Browser sort is not stable
Timer 47cd783
Fix ordering of final message
Timer cf897f0
Register the warning capture
Timer a150609
Display only createElement warnings
Timer 8dfb007
Use different method name
Timer 4bae90d
Fix regression
Timer ab81262
Ignore errors with only node_module files
Timer 79af0fc
Ignore null files, too
Timer ec12b8c
Revise count
Timer fb7411b
Revise warning
Timer cd9c43f
Update overlay.js
Timer 83e6324
Add support for https://github.com/facebook/react/pull/9679
Timer ede4f9b
Use absolute paths
Timer 8997f58
Trim path if it's absolute
Timer 19eadc2
Make sure it's an absolute path
Timer 43a97e3
Oops
Timer 52a39a4
Tweak for new behavior
gaearon 4d9f647
Make it safer
gaearon d7f81e7
More resilient warnings
gaearon 2d4fdad
Merge branch 'master' into unmapper-fix
gaearon 4cb6be3
Prettier output
gaearon 11fc0f0
Merge remote-tracking branch 'Timer/unmapper-fix' into Timer-unmapper…
gaearon 9da83b3
Fix flow
gaearon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,48 @@ | ||
/* @flow */ | ||
type ConsoleProxyCallback = (message: string) => void; | ||
|
||
type ReactFrame = { | ||
fileName: string | null, | ||
lineNumber: number | null, | ||
functionName: string | null, | ||
}; | ||
const reactFrameStack: Array<ReactFrame[]> = []; | ||
|
||
export type { ReactFrame }; | ||
|
||
const registerReactStack = () => { | ||
// $FlowFixMe | ||
console.stack = frames => reactFrameStack.push(frames); | ||
// $FlowFixMe | ||
console.stackEnd = frames => reactFrameStack.pop(); | ||
}; | ||
|
||
const unregisterReactStack = () => { | ||
// $FlowFixMe | ||
console.stack = undefined; | ||
// $FlowFixMe | ||
console.stackEnd = undefined; | ||
}; | ||
|
||
type ConsoleProxyCallback = (message: string, frames: ReactFrame[]) => void; | ||
const permanentRegister = function proxyConsole( | ||
type: string, | ||
callback: ConsoleProxyCallback | ||
) { | ||
const orig = console[type]; | ||
console[type] = function __stack_frame_overlay_proxy_console__() { | ||
const message = [].slice.call(arguments).join(' '); | ||
callback(message); | ||
try { | ||
const message = arguments[0]; | ||
if (typeof message === 'string' && reactFrameStack.length > 0) { | ||
callback(message, reactFrameStack[reactFrameStack.length - 1]); | ||
} | ||
} catch (err) { | ||
// Warnings must never crash. Rethrow with a clean stack. | ||
setTimeout(function() { | ||
throw err; | ||
}); | ||
} | ||
return orig.apply(this, arguments); | ||
}; | ||
}; | ||
|
||
export { permanentRegister }; | ||
export { permanentRegister, registerReactStack, unregisterReactStack }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// @flow | ||
import type { ReactFrame } from '../effects/proxyConsole'; | ||
|
||
function stripInlineStacktrace(message: string): string { | ||
return message.split('\n').filter(line => !line.match(/^\s*in/)).join('\n'); // " in Foo" | ||
} | ||
|
||
function massage( | ||
warning: string, | ||
frames: ReactFrame[] | ||
): { message: string, stack: string } { | ||
let message = stripInlineStacktrace(warning); | ||
|
||
// Reassemble the stack with full filenames provided by React | ||
let stack = ''; | ||
for (let index = 0; index < frames.length; ++index) { | ||
const { fileName, lineNumber } = frames[index]; | ||
if (fileName == null || lineNumber == null) { | ||
continue; | ||
} | ||
let { functionName } = frames[index]; | ||
functionName = functionName || '(anonymous function)'; | ||
stack += `in ${functionName} (at ${fileName}:${lineNumber})\n`; | ||
} | ||
|
||
return { message, stack }; | ||
} | ||
|
||
export { massage }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
That's better thanks!