Skip to content

Commit 455424d

Browse files
authored
[devtools] fix: fallback to reading string stack trace when failed (#33700)
Discovered while testing with Hermes.
1 parent 9fd4c09 commit 455424d

File tree

1 file changed

+8
-1
lines changed
  • packages/react-devtools-shared/src/backend/utils

1 file changed

+8
-1
lines changed

packages/react-devtools-shared/src/backend/utils/index.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ function collectStackTrace(
381381
// $FlowFixMe[prop-missing]
382382
typeof callSite.getEnclosingColumnNumber === 'function'
383383
? (callSite: any).getEnclosingColumnNumber()
384-
: callSite.getLineNumber();
384+
: callSite.getColumnNumber();
385385
if (!sourceURL || !line || !col) {
386386
// Skip eval etc. without source url. They don't have location.
387387
continue;
@@ -412,12 +412,19 @@ export function parseSourceFromOwnerStack(error: Error): Source | null {
412412
let stack;
413413
try {
414414
stack = error.stack;
415+
} catch (e) {
416+
// $FlowFixMe[incompatible-type] It does accept undefined.
417+
Error.prepareStackTrace = undefined;
418+
stack = error.stack;
415419
} finally {
416420
Error.prepareStackTrace = previousPrepare;
417421
}
418422
if (collectedLocation !== null) {
419423
return collectedLocation;
420424
}
425+
if (stack == null) {
426+
return null;
427+
}
421428
// Fallback to parsing the string form.
422429
const componentStack = formatOwnerStackString(stack);
423430
return parseSourceFromComponentStack(componentStack);

0 commit comments

Comments
 (0)