Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 67 additions & 54 deletions packages/react-native/Libraries/LogBox/Data/parseLogBoxLog.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,68 @@ export function parseLogBoxException(
const message =
error.originalMessage != null ? error.originalMessage : 'Unknown';

const metroInternalError = message.match(RE_METRO_ERROR_FORMAT);
const bundlingError = parseBundlingErrorFromMessage(message);
if (bundlingError) {
return bundlingError;
}

const componentStack = error.componentStack;
if (error.isFatal || error.isComponentError) {
if (componentStack != null) {
const {type, stack} = parseComponentStack(componentStack);
return {
level: 'fatal',
stack: error.stack,
isComponentError: error.isComponentError,
componentStackType: type,
componentStack: stack,
extraData: error.extraData,
...parseInterpolation([message]),
};
} else {
return {
level: 'fatal',
stack: error.stack,
isComponentError: error.isComponentError,
componentStackType: 'legacy',
componentStack: [],
extraData: error.extraData,
...parseInterpolation([message]),
};
}
}

if (componentStack != null) {
// It is possible that console errors have a componentStack.
const {type, stack} = parseComponentStack(componentStack);
return {
level: 'error',
stack: error.stack,
isComponentError: error.isComponentError,
componentStackType: type,
componentStack: stack,
extraData: error.extraData,
...parseInterpolation([message]),
};
}

// Most `console.error` calls won't have a componentStack. We parse them like
// regular logs which have the component stack buried in the message.
return {
level: 'error',
stack: error.stack,
isComponentError: error.isComponentError,
extraData: error.extraData,
...parseLogBoxLog([message]),
};
}

export function parseBundlingErrorFromMessage(message?: string, extraData?: Object): LogBoxLogData | null {
if (!message || typeof message !== 'string') {
return null;
}

const metroInternalError = message.match(RE_METRO_ERROR_FORMAT);
if (metroInternalError) {
const [content, fileName, row, column, codeFrame] =
metroInternalError.slice(1);
Expand All @@ -315,7 +376,7 @@ export function parseLogBoxException(
substitutions: [],
},
category: `${fileName}-${row}-${column}`,
extraData: error.extraData,
extraData,
};
}

Expand Down Expand Up @@ -344,7 +405,7 @@ export function parseLogBoxException(
substitutions: [],
},
category: `${fileName}-${row}-${column}`,
extraData: error.extraData,
extraData,
};
}

Expand Down Expand Up @@ -372,7 +433,7 @@ export function parseLogBoxException(
substitutions: [],
},
category: `${fileName}-${1}-${1}`,
extraData: error.extraData,
extraData,
};
}
}
Expand All @@ -389,59 +450,11 @@ export function parseLogBoxException(
substitutions: [],
},
category: message,
extraData: error.extraData,
};
}

const componentStack = error.componentStack;
if (error.isFatal || error.isComponentError) {
if (componentStack != null) {
const {type, stack} = parseComponentStack(componentStack);
return {
level: 'fatal',
stack: error.stack,
isComponentError: error.isComponentError,
componentStackType: type,
componentStack: stack,
extraData: error.extraData,
...parseInterpolation([message]),
};
} else {
return {
level: 'fatal',
stack: error.stack,
isComponentError: error.isComponentError,
componentStackType: 'legacy',
componentStack: [],
extraData: error.extraData,
...parseInterpolation([message]),
};
}
}

if (componentStack != null) {
// It is possible that console errors have a componentStack.
const {type, stack} = parseComponentStack(componentStack);
return {
level: 'error',
stack: error.stack,
isComponentError: error.isComponentError,
componentStackType: type,
componentStack: stack,
extraData: error.extraData,
...parseInterpolation([message]),
extraData,
};
}

// Most `console.error` calls won't have a componentStack. We parse them like
// regular logs which have the component stack buried in the message.
return {
level: 'error',
stack: error.stack,
isComponentError: error.isComponentError,
extraData: error.extraData,
...parseLogBoxLog([message]),
};
return null;
}

export function withoutANSIColorStyles(message: mixed): mixed {
Expand Down
15 changes: 15 additions & 0 deletions packages/react-native/Libraries/LogBox/LogBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ if (__DEV__) {
const {
parseLogBoxLog,
parseComponentStack,
parseBundlingErrorFromMessage,
} = require('./Data/parseLogBoxLog');

let originalConsoleWarn;
Expand Down Expand Up @@ -166,6 +167,20 @@ if (__DEV__) {
}
}

// Ensure bundling errors are parsed before anything else.
// This ensures bundling errors are not symbolicated
// (symbolication would fail since the bundle & source map won't be created)
const bundlingError = parseBundlingErrorFromMessage(
// If args[0] is a string use it directly, otherwise try to extract message property
typeof args[0] === 'string'
? args[0]
: typeof args[0]?.message === 'string'
? args[0].message
: undefined)
if (bundlingError) {
return LogBoxData.addLog(bundlingError);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the wrong place for this


const result = parseLogBoxLog(args);
const category = result.category;
const message = result.message;
Expand Down
Loading