Fix failed to get caller location throws

pull/2157/head
Tony 8 months ago
parent fe610d6759
commit a0b3fc8a66
No known key found for this signature in database
GPG Key ID: 34BDD3EA27824956

@ -60,11 +60,11 @@ function getCallerLocation(stack?: string) {
const lines = stack.split('\n') const lines = stack.split('\n')
// Find the third line (caller's caller of the current location) // Find the third line (caller's caller of the current location)
const callerLine = lines[3].trim() const callerLine = lines[3]?.trim()
const regex = const regex =
/at\s+(?<functionName>.*?)\s+\((?<fileName>.*?):(?<lineNumber>\d+):(?<columnNumber>\d+)\)/ /at\s+(?<functionName>.*?)\s+\((?<fileName>.*?):(?<lineNumber>\d+):(?<columnNumber>\d+)\)/
const match = callerLine.match(regex) const match = callerLine?.match(regex)
if (match) { if (match) {
const { functionName, fileName, lineNumber, columnNumber } = const { functionName, fileName, lineNumber, columnNumber } =
@ -79,7 +79,7 @@ function getCallerLocation(stack?: string) {
// Handle cases where the regex does not match (e.g., last line without function name) // Handle cases where the regex does not match (e.g., last line without function name)
const regexNoFunction = const regexNoFunction =
/at\s+(?<fileName>.*?):(?<lineNumber>\d+):(?<columnNumber>\d+)/ /at\s+(?<fileName>.*?):(?<lineNumber>\d+):(?<columnNumber>\d+)/
const matchNoFunction = callerLine.match(regexNoFunction) const matchNoFunction = callerLine?.match(regexNoFunction)
if (matchNoFunction) { if (matchNoFunction) {
const { fileName, lineNumber, columnNumber } = const { fileName, lineNumber, columnNumber } =
matchNoFunction.groups as { matchNoFunction.groups as {
@ -103,7 +103,7 @@ function getCallerLocation(stack?: string) {
return name.length > 0 && location !== '[native code]' return name.length > 0 && location !== '[native code]'
}) })
// Find the third line (caller's caller of the current location) // Find the third line (caller's caller of the current location)
return filtered[2].filter((v) => v.length > 0).join('@') return filtered[2]?.filter((v) => v.length > 0).join('@')
} }
} }

Loading…
Cancel
Save