Describe the bug
a undefined not handle by prettyFormatErrorObj then call the getErrorTrace .
Screenshots

To Reproduce
this is a large project, so i checked into the code. and finded the bug.
the error throw from this line :
|
const errorStackStr = getErrorTrace(error as Error).map((stackFrame) => { |
it tell me Cannot read properties of undefined (reading 'map') at prettyFormatErrorObj .
so , we can kwon that , the return of getErrorTrace() is undefined .
when we see the function getErrorTrace() we can find that :
|
export function getErrorTrace(error: Error): IStackFrame[] { |
|
return (error as Error)?.stack?.split("\n")?.reduce((result: IStackFrame[], line: string) => { |
|
if (line.includes(" at ")) { |
|
result.push(stackLineToStackFrame(line)); |
|
} |
|
return result; |
|
}, []) as IStackFrame[]; |
|
} |
the function getErrorTrace() is return undefined | IStackFrame[] not IStackFrame[] .
because the function use ?. chain .
and after i search all code , i find that the browser version code was fixed this issue.
|
export function getErrorTrace(error: Error): IStackFrame[] { |
|
return ((error as Error)?.stack?.split("\n") ?? []) |
|
?.filter((line: string) => !line.includes("Error: ")) |
|
?.reduce((result: IStackFrame[], line: string) => { |
|
result.push(stackLineToStackFrame(line)); |
|
|
|
return result; |
|
}, []) as IStackFrame[]; |
|
} |
it fix by a ?? [] simply .
Expected behavior
simple write code like browser , then all will work.
the right code maybe like here :
export function getErrorTrace(error: Error): IStackFrame[] {
return ((error as Error)?.stack?.split("\n") ?? []).reduce((result: IStackFrame[], line: string) => {
if (line.includes(" at ")) {
result.push(stackLineToStackFrame(line));
}
return result;
}, []) as IStackFrame[];
}
Node.js Version
v20.12.2
OS incl. Version
win10
Describe the bug
a undefined not handle by
prettyFormatErrorObjthen call thegetErrorTrace.Screenshots

To Reproduce
this is a large project, so i checked into the code. and finded the bug.
the error throw from this line :
tslog/src/runtime/nodejs/index.ts
Line 129 in 9a5d156
it tell me
Cannot read properties of undefined (reading 'map') at prettyFormatErrorObj.so , we can kwon that , the return of
getErrorTrace()is undefined .when we see the function
getErrorTrace()we can find that :tslog/src/runtime/nodejs/index.ts
Lines 64 to 71 in 9a5d156
the function
getErrorTrace()is returnundefined | IStackFrame[]notIStackFrame[].because the function use
?.chain .and after i search all code , i find that the browser version code was fixed this issue.
tslog/src/runtime/browser/index.ts
Lines 64 to 72 in 9a5d156
it fix by a
?? []simply .Expected behavior
simple write code like browser , then all will work.
the right code maybe like here :
Node.js Version
v20.12.2
OS incl. Version
win10