[devtools] fix: fallback to reading string stack trace when failed (#33700)

Discovered while testing with Hermes.
This commit is contained in:
Ruslan Lesiutin
2025-07-04 15:36:52 +01:00
committed by GitHub
parent 9fd4c09d68
commit 455424dbf3

View File

@@ -381,7 +381,7 @@ function collectStackTrace(
// $FlowFixMe[prop-missing]
typeof callSite.getEnclosingColumnNumber === 'function'
? (callSite: any).getEnclosingColumnNumber()
: callSite.getLineNumber();
: callSite.getColumnNumber();
if (!sourceURL || !line || !col) {
// Skip eval etc. without source url. They don't have location.
continue;
@@ -412,12 +412,19 @@ export function parseSourceFromOwnerStack(error: Error): Source | null {
let stack;
try {
stack = error.stack;
} catch (e) {
// $FlowFixMe[incompatible-type] It does accept undefined.
Error.prepareStackTrace = undefined;
stack = error.stack;
} finally {
Error.prepareStackTrace = previousPrepare;
}
if (collectedLocation !== null) {
return collectedLocation;
}
if (stack == null) {
return null;
}
// Fallback to parsing the string form.
const componentStack = formatOwnerStackString(stack);
return parseSourceFromComponentStack(componentStack);