From 29b227b620a077211bc87fad6238da8462bad406 Mon Sep 17 00:00:00 2001 From: ejose19 <8742215+ejose19@users.noreply.github.com> Date: Sat, 27 Nov 2021 20:01:54 -0300 Subject: [PATCH] Exclude error name from "IErrorObject" --- src/LoggerWithoutCallSite.ts | 8 +++++++- tests/error.test.ts | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/LoggerWithoutCallSite.ts b/src/LoggerWithoutCallSite.ts index cde620b8..62061665 100644 --- a/src/LoggerWithoutCallSite.ts +++ b/src/LoggerWithoutCallSite.ts @@ -456,9 +456,15 @@ export class LoggerWithoutCallSite { relevantCallSites.length = stackLimit; } + const { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + name: _name, + ...errorWithoutName + } = error; + const errorObject: IErrorObject = { nativeError: error, - details: { ...error }, + details: { ...errorWithoutName }, name: error.name ?? "Error", isError: true, message: error.message, diff --git a/tests/error.test.ts b/tests/error.test.ts index 5a5ad41f..0a5bc1fc 100644 --- a/tests/error.test.ts +++ b/tests/error.test.ts @@ -55,6 +55,7 @@ describe("Logger: Error with details", () => { loggerPretty.warn(error); expect(doesLogContain(stdErr, "TestError")).toBeTruthy(); expect(doesLogContain(stdErr, ".test.ts")).toBeTruthy(); + expect(doesLogContain(stdErr, "details:")).toBeFalsy(); }); test("JSON: Error with details (stdErr)", (): void => { @@ -62,6 +63,7 @@ describe("Logger: Error with details", () => { loggerJson.warn(error); expect(doesLogContain(stdErr, "TestError")).toBeTruthy(); expect(doesLogContain(stdErr, ".test.ts")).toBeTruthy(); + expect(doesLogContain(stdErr, '"details":{}')).toBeTruthy(); }); test("JSON: Check if call site wrapping is working (Bugfix: #29)", (): void => {