diff --git a/src/main.spec.ts b/src/main.spec.ts index c0deeb31..bb7ff7bf 100644 --- a/src/main.spec.ts +++ b/src/main.spec.ts @@ -20,8 +20,7 @@ vi.mock("./action.ts"); vi.mock("./api.ts"); describe("main", () => { - const { coreDebugLogMock, coreErrorLogMock, assertOnlyCalled } = - mockLoggingFunctions(); + const { coreDebugLogMock, assertOnlyCalled } = mockLoggingFunctions(); const testCfg: action.ActionConfig = { ref: "test-ref", workflow: "test-workflow", @@ -109,8 +108,7 @@ describe("main", () => { ); // Logging - assertOnlyCalled(coreDebugLogMock, coreErrorLogMock); - expect(coreErrorLogMock).toHaveBeenCalledOnce(); + assertOnlyCalled(coreDebugLogMock); expect(coreDebugLogMock.mock.calls[0]?.[0]).toStrictEqual(testError.stack); }); @@ -135,11 +133,7 @@ describe("main", () => { ); // Logging - assertOnlyCalled(coreDebugLogMock, coreErrorLogMock); - expect(coreErrorLogMock).toHaveBeenCalledOnce(); - expect(coreErrorLogMock.mock.calls[0]?.[0]).toMatchInlineSnapshot( - `"Failed: An unhandled error has occurred: test error"`, - ); + assertOnlyCalled(coreDebugLogMock); expect(coreDebugLogMock).toHaveBeenCalledOnce(); expect(coreDebugLogMock.mock.calls[0]?.[0]).toStrictEqual(testError.stack); }); @@ -166,11 +160,7 @@ describe("main", () => { ); // Logging - assertOnlyCalled(coreDebugLogMock, coreErrorLogMock); - expect(coreErrorLogMock).toHaveBeenCalledOnce(); - expect(coreErrorLogMock.mock.calls[0]?.[0]).toMatchInlineSnapshot( - `"Failed: An unknown error has occurred: some other error"`, - ); + assertOnlyCalled(coreDebugLogMock); expect(coreDebugLogMock).toHaveBeenCalledOnce(); expect(coreDebugLogMock.mock.calls[0]?.[0]).toStrictEqual(testError); }); diff --git a/src/main.ts b/src/main.ts index 32142c10..2f2cd612 100644 --- a/src/main.ts +++ b/src/main.ts @@ -18,15 +18,13 @@ export async function main(): Promise { core.debug(`Completed (${Date.now() - startTime}ms)`); } catch (error) { if (error instanceof Error) { - const failureMsg = `Failed: An unhandled error has occurred: ${error.message}`; - core.setFailed(failureMsg); - core.error(failureMsg); + core.setFailed( + `Failed: An unhandled error has occurred: ${error.message}`, + ); core.debug(error.stack ?? ""); } else { // eslint-disable-next-line @typescript-eslint/restrict-template-expressions - const failureMsg = `Failed: An unknown error has occurred: ${error}`; - core.setFailed(failureMsg); - core.error(failureMsg); + core.setFailed(`Failed: An unknown error has occurred: ${error}`); // eslint-disable-next-line @typescript-eslint/no-unsafe-argument core.debug(error as any); }