chore(lib/utils/errors): make getCurrentStack a little more performant

This commit is contained in:
PalmDevs 2025-06-13 22:47:28 +07:00
parent 2852211a91
commit 7953056b94
No known key found for this signature in database
GPG key ID: 6FAE8F8677ACA8BA

View file

@ -4,5 +4,12 @@ export function getErrorStack(e: unknown) {
export function getCurrentStack() {
const { stack } = new Error()
return stack!.split('\n').slice(2).join('\n')
let newlineCount = 0
for (let i = 0; i < stack!.length; i++)
if (stack![i] === '\n' && newlineCount++ === 1)
return stack!.slice(i + 1)
return stack!.slice(stack!.indexOf('\n') + 1)
}