Skip to content

Commit 69d508e

Browse files
fix(log): prevent thowing on failed to get caller location (#2157)
* Fix failed to get caller location throws * Add change file * typo * build * Bump log rs * typo * early return instead of using ?
1 parent fe610d6 commit 69d508e

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"log": patch
3+
"log-js": patch
4+
---
5+
6+
Make log functions omit caller location when failed to parse it instead of throwing

plugins/log/api-iife.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/log/guest-js/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ function getCallerLocation(stack?: string) {
6060

6161
const lines = stack.split('\n')
6262
// Find the third line (caller's caller of the current location)
63-
const callerLine = lines[3].trim()
63+
const callerLine = lines[3]?.trim()
64+
if (!callerLine) {
65+
return
66+
}
6467

6568
const regex =
6669
/at\s+(?<functionName>.*?)\s+\((?<fileName>.*?):(?<lineNumber>\d+):(?<columnNumber>\d+)\)/
@@ -103,7 +106,7 @@ function getCallerLocation(stack?: string) {
103106
return name.length > 0 && location !== '[native code]'
104107
})
105108
// Find the third line (caller's caller of the current location)
106-
return filtered[2].filter((v) => v.length > 0).join('@')
109+
return filtered[2]?.filter((v) => v.length > 0).join('@')
107110
}
108111
}
109112

0 commit comments

Comments
 (0)