From 9a74eb4e6473f91fbde564f97c2662fd1dc4875c Mon Sep 17 00:00:00 2001 From: Dmitry Shibanov Date: Mon, 27 Dec 2021 12:34:06 +0300 Subject: [PATCH 1/2] Throw error only if exit code is note zero. (#358) --- .github/workflows/licensed.yml | 2 +- dist/cache-save/index.js | 7 +++++-- dist/setup/index.js | 7 +++++-- src/cache-utils.ts | 11 +++++++++-- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/.github/workflows/licensed.yml b/.github/workflows/licensed.yml index 4c1dfe5fb..4f485f5f9 100644 --- a/.github/workflows/licensed.yml +++ b/.github/workflows/licensed.yml @@ -18,7 +18,7 @@ jobs: - name: Install licensed run: | cd $RUNNER_TEMP - curl -Lfs -o licensed.tar.gz https://github.com/github/licensed/releases/download/2.12.2/licensed-2.12.2-linux-x64.tar.gz + curl -Lfs -o licensed.tar.gz https://github.com/github/licensed/releases/download/3.3.1/licensed-3.3.1-linux-x64.tar.gz sudo tar -xzf licensed.tar.gz sudo mv licensed /usr/local/bin/licensed - run: licensed status diff --git a/dist/cache-save/index.js b/dist/cache-save/index.js index 2a86dfebd..b24c7c9c4 100644 --- a/dist/cache-save/index.js +++ b/dist/cache-save/index.js @@ -3836,8 +3836,11 @@ exports.supportedPackageManagers = { } }; exports.getCommandOutput = (toolCommand) => __awaiter(void 0, void 0, void 0, function* () { - const { stdout, stderr, exitCode } = yield exec.getExecOutput(toolCommand); - if (stderr) { + let { stdout, stderr, exitCode } = yield exec.getExecOutput(toolCommand, undefined, { ignoreReturnCode: true }); + if (exitCode) { + stderr = !stderr.trim() + ? `The '${toolCommand}' command failed with exit code: ${exitCode}` + : stderr; throw new Error(stderr); } return stdout.trim(); diff --git a/dist/setup/index.js b/dist/setup/index.js index 1dc2f2f5e..c6a63f284 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -46207,8 +46207,11 @@ exports.supportedPackageManagers = { } }; exports.getCommandOutput = (toolCommand) => __awaiter(void 0, void 0, void 0, function* () { - const { stdout, stderr, exitCode } = yield exec.getExecOutput(toolCommand); - if (stderr) { + let { stdout, stderr, exitCode } = yield exec.getExecOutput(toolCommand, undefined, { ignoreReturnCode: true }); + if (exitCode) { + stderr = !stderr.trim() + ? `The '${toolCommand}' command failed with exit code: ${exitCode}` + : stderr; throw new Error(stderr); } return stdout.trim(); diff --git a/src/cache-utils.ts b/src/cache-utils.ts index ebea9a750..36531bd58 100644 --- a/src/cache-utils.ts +++ b/src/cache-utils.ts @@ -30,9 +30,16 @@ export const supportedPackageManagers: SupportedPackageManagers = { }; export const getCommandOutput = async (toolCommand: string) => { - const {stdout, stderr, exitCode} = await exec.getExecOutput(toolCommand); + let {stdout, stderr, exitCode} = await exec.getExecOutput( + toolCommand, + undefined, + {ignoreReturnCode: true} + ); - if (stderr) { + if (exitCode) { + stderr = !stderr.trim() + ? `The '${toolCommand}' command failed with exit code: ${exitCode}` + : stderr; throw new Error(stderr); } From 1f8c6b94b26d0feae1e387ca63ccbdc44d27b561 Mon Sep 17 00:00:00 2001 From: Dmitry Shibanov Date: Tue, 28 Dec 2021 12:25:43 +0300 Subject: [PATCH 2/2] Pass to warning uncaught exceptions (#359) --- dist/cache-save/index.js | 7 +++++++ src/cache-save.ts | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/dist/cache-save/index.js b/dist/cache-save/index.js index b24c7c9c4..f0b1b3225 100644 --- a/dist/cache-save/index.js +++ b/dist/cache-save/index.js @@ -46979,6 +46979,13 @@ const cache = __importStar(__webpack_require__(692)); const fs_1 = __importDefault(__webpack_require__(747)); const constants_1 = __webpack_require__(196); const cache_utils_1 = __webpack_require__(143); +// Catch and log any unhandled exceptions. These exceptions can leak out of the uploadChunk method in +// @actions/toolkit when a failed upload closes the file descriptor causing any in-process reads to +// throw an uncaught exception. Instead of failing this action, just warn. +process.on('uncaughtException', e => { + const warningPrefix = '[warning]'; + core.info(`${warningPrefix}${e.message}`); +}); function run() { return __awaiter(this, void 0, void 0, function* () { try { diff --git a/src/cache-save.ts b/src/cache-save.ts index 9fb0b29d6..34115559b 100644 --- a/src/cache-save.ts +++ b/src/cache-save.ts @@ -4,6 +4,14 @@ import fs from 'fs'; import {State} from './constants'; import {getCacheDirectoryPath, getPackageManagerInfo} from './cache-utils'; +// Catch and log any unhandled exceptions. These exceptions can leak out of the uploadChunk method in +// @actions/toolkit when a failed upload closes the file descriptor causing any in-process reads to +// throw an uncaught exception. Instead of failing this action, just warn. +process.on('uncaughtException', e => { + const warningPrefix = '[warning]'; + core.info(`${warningPrefix}${e.message}`); +}); + export async function run() { try { const cacheLock = core.getInput('cache');