fix error capture
This commit is contained in:
@@ -1,34 +1,12 @@
|
|||||||
import 'array.prototype.findlast/auto'
|
import 'array.prototype.findlast/auto'
|
||||||
import 'setimmediate'
|
import 'setimmediate'
|
||||||
|
|
||||||
if (process.env.NODE_ENV !== 'production') {
|
/*
|
||||||
// In development, react-native-web's <View> tries to validate that
|
* NOTE: the webpack-era console.error wrapper that re-threw react-native-web's
|
||||||
// text is wrapped into <Text>. It doesn't catch all cases but is useful.
|
* "Unexpected text node" warnings as redboxes was removed with the Metro
|
||||||
// Unfortunately, it only does that via console.error so it's easy to miss.
|
* migration. Metro's LogBox already surfaces console.error prominently, and
|
||||||
// This is a hack to get it showing as a redbox on the web so we catch it early.
|
* any wrapper around console.error becomes the top stack frame of every
|
||||||
const realConsoleError = console.error
|
* captured error, making Metro attribute all of them to this file.
|
||||||
const thrownErrors = new WeakSet()
|
*/
|
||||||
console.error = function consoleErrorWrapper(msgOrError) {
|
|
||||||
if (
|
|
||||||
typeof msgOrError === 'string' &&
|
|
||||||
msgOrError.startsWith('Unexpected text node')
|
|
||||||
) {
|
|
||||||
if (
|
|
||||||
msgOrError ===
|
|
||||||
'Unexpected text node: . A text node cannot be a child of a <View>.'
|
|
||||||
) {
|
|
||||||
// This is due to a stray empty string.
|
|
||||||
// React already handles this fine, so RNW warning is a false positive. Ignore.
|
|
||||||
return
|
|
||||||
}
|
|
||||||
const err = new Error(msgOrError)
|
|
||||||
thrownErrors.add(err)
|
|
||||||
throw err
|
|
||||||
} else if (!thrownErrors.has(msgOrError)) {
|
|
||||||
// @ts-expect-error
|
|
||||||
return realConsoleError.apply(this, arguments)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export {}
|
export {}
|
||||||
|
|||||||
Reference in New Issue
Block a user