Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 4 additions & 14 deletions src/main.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -109,8 +108,7 @@ describe("main", () => {
);

// Logging
assertOnlyCalled(coreDebugLogMock, coreErrorLogMock);
expect(coreErrorLogMock).toHaveBeenCalledOnce();
assertOnlyCalled(coreDebugLogMock);
expect(coreDebugLogMock.mock.calls[0]?.[0]).toStrictEqual(testError.stack);
});

Expand All @@ -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);
});
Expand All @@ -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);
});
Expand Down
10 changes: 4 additions & 6 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@ export async function main(): Promise<void> {
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);
}
Expand Down
Loading