From 99bce34715b90d4baec83db6faee5ca958cffd70 Mon Sep 17 00:00:00 2001 From: LyokoJeremie Date: Mon, 23 Dec 2024 13:34:04 +0800 Subject: [PATCH] fix getErrorTrace fix Cannot read properties of undefined (reading 'map') at prettyFormatErrorObj . https://github.com/fullstack-build/tslog/issues/311 --- src/runtime/nodejs/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/runtime/nodejs/index.ts b/src/runtime/nodejs/index.ts index 6aa0793..fd7df6f 100644 --- a/src/runtime/nodejs/index.ts +++ b/src/runtime/nodejs/index.ts @@ -62,12 +62,12 @@ export function getCallerStackFrame(stackDepthLevel: number, error: Error = Erro } export function getErrorTrace(error: Error): IStackFrame[] { - return (error as Error)?.stack?.split("\n")?.reduce((result: IStackFrame[], line: string) => { + return ((error as Error)?.stack?.split("\n") ?? []).reduce((result: IStackFrame[], line: string) => { if (line.includes(" at ")) { result.push(stackLineToStackFrame(line)); } return result; - }, []) as IStackFrame[]; + }, []); } function stackLineToStackFrame(line?: string): IStackFrame {