Skip to content

Commit 763dc35

Browse files
terriblebenthotegowda
authored andcommitted
Protect against fatal YellowBox error when stack frame has no file
Summary: Motivation: When viewing a stack trace in YellowBox where one or more of the stack frames has no `file`, JS will encounter the fatal error `null is not an object (evaluating 'file.split')`. This can happen, for example, when running a bundle for which no source maps were generated. Closes facebook#13512 Differential Revision: D4896480 Pulled By: javache fbshipit-source-id: 202c793a47abb83a4700a5778a92b0b5828b01a3
1 parent d081026 commit 763dc35

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

Libraries/ReactNative/YellowBox.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,13 @@ const StackRow = ({frame}: StackRowProps) => {
191191
const Text = require('Text');
192192
const TouchableHighlight = require('TouchableHighlight');
193193
const {file, lineNumber} = frame;
194-
const fileParts = file.split('/');
195-
const fileName = fileParts[fileParts.length - 1];
194+
let fileName;
195+
if (file) {
196+
const fileParts = file.split('/');
197+
fileName = fileParts[fileParts.length - 1];
198+
} else {
199+
fileName = '<unknown file>';
200+
}
196201

197202
return (
198203
<TouchableHighlight

0 commit comments

Comments
 (0)