Skip to content

Commit 5b01a1c

Browse files
committed
feat: add parseStack function
1 parent a45e8e4 commit 5b01a1c

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/exception.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ interface ExceptionLike extends Error, ExceptionOptions {
6363
toString(): string;
6464
}
6565

66+
function parseStack(error: Error): string[] {
67+
return extractStack.lines(cleanStack(error.stack, { pretty: true }));
68+
}
69+
6670
abstract class BaseException<TParams extends ExceptionParams, TOptions extends ExceptionOptions>
6771
extends Error
6872
implements ExceptionLike
@@ -107,7 +111,7 @@ abstract class BaseException<TParams extends ExceptionParams, TOptions extends E
107111

108112
private formatError(error: Error & { details?: { [key: string]: unknown } }): string {
109113
const result = [`${error.name}: ${error.message}`];
110-
extractStack.lines(cleanStack(error.stack, { pretty: true })).forEach((line) => {
114+
parseStack(error).forEach((line) => {
111115
result.push(` at ${line}`);
112116
});
113117
if (error.details) {
@@ -224,4 +228,4 @@ export type {
224228
ExceptionStatic,
225229
ExceptionType
226230
};
227-
export { BaseException, ExceptionBuilder, OutOfRangeException, RuntimeException, ValueException };
231+
export { BaseException, ExceptionBuilder, OutOfRangeException, parseStack, RuntimeException, ValueException };

0 commit comments

Comments
 (0)