From 28ad38fe0624edc69ffde19aa0a6b8be0573641f Mon Sep 17 00:00:00 2001 From: Dmitry Shibanov Date: Tue, 12 Jul 2022 10:45:50 +0200 Subject: [PATCH] add try catch --- dist/setup/index.js | 18 +++++++----------- src/main.ts | 21 ++++++++++----------- 2 files changed, 17 insertions(+), 22 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index 31aa5cc8..f203ff6a 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -71846,17 +71846,13 @@ function run() { yield installer.getNode(version, stable, checkLatest, auth, arch); } // Output version of node is being used - let installedVersion = ''; - const result = yield exec.exec('node', ['--version'], { - ignoreReturnCode: true, - silent: false, - listeners: { - stdout: data => { - installedVersion = data.toString(); - } - } - }); - core.setOutput('node-version', installedVersion); + try { + const { stdout: installedVersion } = yield exec.getExecOutput('node', ['--version'], { ignoreReturnCode: true, silent: false }); + core.setOutput('node-version', installedVersion); + } + catch (err) { + core.setOutput('node-version', ''); + } const registryUrl = core.getInput('registry-url'); const alwaysAuth = core.getInput('always-auth'); if (registryUrl) { diff --git a/src/main.ts b/src/main.ts index 88f99e01..57f19229 100644 --- a/src/main.ts +++ b/src/main.ts @@ -41,17 +41,16 @@ export async function run() { } // Output version of node is being used - let installedVersion = ''; - const result = await exec.exec('node', ['--version'], { - ignoreReturnCode: true, - silent: false, - listeners: { - stdout: data => { - installedVersion = data.toString(); - } - } - }); - core.setOutput('node-version', installedVersion); + try { + const {stdout: installedVersion} = await exec.getExecOutput( + 'node', + ['--version'], + {ignoreReturnCode: true, silent: false} + ); + core.setOutput('node-version', installedVersion); + } catch (err) { + core.setOutput('node-version', ''); + } const registryUrl: string = core.getInput('registry-url'); const alwaysAuth: string = core.getInput('always-auth');