Skip to content

Commit 6931e3c

Browse files
authored
fix: output error stacktraces in debug mode (#160)
* chore: add test case to output stack traces * fix: add error stacktraces to debug
1 parent 3f293ee commit 6931e3c

4 files changed

Lines changed: 43 additions & 7 deletions

File tree

build/preview-comment/index.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16021,9 +16021,16 @@ Object.defineProperty(exports, "findTool", ({ enumerable: true, get: function ()
1602116021
Object.defineProperty(exports, "cacheTool", ({ enumerable: true, get: function () { return tool_cache_1.cacheDir; } }));
1602216022
/**
1602316023
* Auto-execute the action and pass errors to 'core.setFailed'.
16024+
* It also passes the full error, with stacktrace, to 'core.debug'.
16025+
* You'll need to enable debugging to view these full errors.
16026+
*
16027+
* @see https://github.com/actions/toolkit/blob/main/docs/action-debugging.md#step-debug-logs
1602416028
*/
16025-
async function executeAction(action) {
16026-
return action().catch(error => (0, core_1.setFailed)(error.message || error));
16029+
function executeAction(action) {
16030+
return action().catch((error) => {
16031+
(0, core_1.setFailed)(error.message || error);
16032+
(0, core_1.debug)(error.stack || 'No stacktrace available');
16033+
});
1602716034
}
1602816035
exports.executeAction = executeAction;
1602916036
/**

build/setup/index.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67067,9 +67067,16 @@ Object.defineProperty(exports, "findTool", ({ enumerable: true, get: function ()
6706767067
Object.defineProperty(exports, "cacheTool", ({ enumerable: true, get: function () { return tool_cache_1.cacheDir; } }));
6706867068
/**
6706967069
* Auto-execute the action and pass errors to 'core.setFailed'.
67070+
* It also passes the full error, with stacktrace, to 'core.debug'.
67071+
* You'll need to enable debugging to view these full errors.
67072+
*
67073+
* @see https://github.com/actions/toolkit/blob/main/docs/action-debugging.md#step-debug-logs
6707067074
*/
67071-
async function executeAction(action) {
67072-
return action().catch(error => (0, core_1.setFailed)(error.message || error));
67075+
function executeAction(action) {
67076+
return action().catch((error) => {
67077+
(0, core_1.setFailed)(error.message || error);
67078+
(0, core_1.debug)(error.stack || 'No stacktrace available');
67079+
});
6707367080
}
6707467081
exports.executeAction = executeAction;
6707567082
/**

src/worker.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { addPath, info, setFailed, warning } from '@actions/core';
1+
import { addPath, debug, info, setFailed, warning } from '@actions/core';
22
import { exec } from '@actions/exec';
33
import { ok as assert } from 'assert';
44
import os from 'os';
@@ -8,9 +8,16 @@ export { find as findTool, cacheDir as cacheTool } from '@actions/tool-cache';
88

99
/**
1010
* Auto-execute the action and pass errors to 'core.setFailed'.
11+
* It also passes the full error, with stacktrace, to 'core.debug'.
12+
* You'll need to enable debugging to view these full errors.
13+
*
14+
* @see https://github.com/actions/toolkit/blob/main/docs/action-debugging.md#step-debug-logs
1115
*/
12-
export async function executeAction(action: () => Promise<void>) {
13-
return action().catch(error => setFailed(error.message || error));
16+
export function executeAction(action: () => Promise<void>) {
17+
return action().catch((error: Error) => {
18+
setFailed(error.message || error);
19+
debug(error.stack || 'No stacktrace available');
20+
});
1421
}
1522

1623
/**

tests/worker.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,19 @@ describe(executeAction, () => {
9292
await expect(executeAction(action)).resolves.not.toThrow();
9393
expect(core.setFailed).toBeCalledWith(error.message);
9494
});
95+
96+
it('provides full stacktrace to debug', async () => {
97+
const error = new Error('fake error');
98+
const action = jest.fn(() => Promise.reject(error));
99+
await expect(executeAction(action)).resolves.not.toThrow();
100+
expect(core.debug).toBeCalledWith(error.stack);
101+
});
102+
103+
it('provides fallback stacktrace to debug', async () => {
104+
const error = new Error('fake error');
105+
error.stack = undefined;
106+
const action = jest.fn(() => Promise.reject(error));
107+
await expect(executeAction(action)).resolves.not.toThrow();
108+
expect(core.debug).toBeCalledWith('No stacktrace available');
109+
});
95110
});

0 commit comments

Comments
 (0)