-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve unmapper file heuristic, add limited warning support, and ign…
…ore internal errors (#2128) * Browser sort is not stable * Fix ordering of final message * Register the warning capture * Display only createElement warnings * Use different method name * Fix regression * Ignore errors with only node_module files * Ignore null files, too * Revise count * Revise warning * Update overlay.js * Add support for facebook/react#9679 * Use absolute paths * Trim path if it's absolute * Make sure it's an absolute path * Oops * Tweak for new behavior * Make it safer * More resilient warnings * Prettier output * Fix flow
- Loading branch information
Showing
8 changed files
with
145 additions
and
32 deletions.
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