From 7953056b9400d2dfdc85d5d52e2b71613ce529f1 Mon Sep 17 00:00:00 2001 From: PalmDevs Date: Fri, 13 Jun 2025 22:47:28 +0700 Subject: [PATCH] chore(lib/utils/errors): make `getCurrentStack` a little more performant --- lib/utils/src/errors.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/utils/src/errors.ts b/lib/utils/src/errors.ts index 610d2e3..df99160 100644 --- a/lib/utils/src/errors.ts +++ b/lib/utils/src/errors.ts @@ -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) }