diff --git a/plugins/log/guest-js/index.ts b/plugins/log/guest-js/index.ts index 6287f913..4233692a 100644 --- a/plugins/log/guest-js/index.ts +++ b/plugins/log/guest-js/index.ts @@ -60,11 +60,11 @@ function getCallerLocation(stack?: string) { const lines = stack.split('\n') // Find the third line (caller's caller of the current location) - const callerLine = lines[3].trim() + const callerLine = lines[3]?.trim() const regex = /at\s+(?.*?)\s+\((?.*?):(?\d+):(?\d+)\)/ - const match = callerLine.match(regex) + const match = callerLine?.match(regex) if (match) { 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) const regexNoFunction = /at\s+(?.*?):(?\d+):(?\d+)/ - const matchNoFunction = callerLine.match(regexNoFunction) + const matchNoFunction = callerLine?.match(regexNoFunction) if (matchNoFunction) { const { fileName, lineNumber, columnNumber } = matchNoFunction.groups as { @@ -103,7 +103,7 @@ function getCallerLocation(stack?: string) { return name.length > 0 && location !== '[native code]' }) // 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('@') } }