Skip to content

Commit

Permalink
fix(log): prevent thowing on failed to get caller location (#2157)
Browse files Browse the repository at this point in the history
* Fix failed to get caller location throws

* Add change file

* typo

* build

* Bump log rs

* typo

* early return instead of using ?
  • Loading branch information
Legend-Master authored Dec 7, 2024
1 parent fe610d6 commit 69d508e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .changes/log-caller-location-throw.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"log": patch
"log-js": patch
---

Make log functions omit caller location when failed to parse it instead of throwing
2 changes: 1 addition & 1 deletion plugins/log/api-iife.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions plugins/log/guest-js/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ 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()
if (!callerLine) {
return
}

const regex =
/at\s+(?<functionName>.*?)\s+\((?<fileName>.*?):(?<lineNumber>\d+):(?<columnNumber>\d+)\)/
Expand Down Expand Up @@ -103,7 +106,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('@')
}
}

Expand Down

0 comments on commit 69d508e

Please sign in to comment.