Skip to content

Commit 28ad38f

Browse files
add try catch
1 parent 48de4c1 commit 28ad38f

File tree

2 files changed

+17
-22
lines changed

2 files changed

+17
-22
lines changed

dist/setup/index.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71846,17 +71846,13 @@ function run() {
7184671846
yield installer.getNode(version, stable, checkLatest, auth, arch);
7184771847
}
7184871848
// Output version of node is being used
71849-
let installedVersion = '';
71850-
const result = yield exec.exec('node', ['--version'], {
71851-
ignoreReturnCode: true,
71852-
silent: false,
71853-
listeners: {
71854-
stdout: data => {
71855-
installedVersion = data.toString();
71856-
}
71857-
}
71858-
});
71859-
core.setOutput('node-version', installedVersion);
71849+
try {
71850+
const { stdout: installedVersion } = yield exec.getExecOutput('node', ['--version'], { ignoreReturnCode: true, silent: false });
71851+
core.setOutput('node-version', installedVersion);
71852+
}
71853+
catch (err) {
71854+
core.setOutput('node-version', '');
71855+
}
7186071856
const registryUrl = core.getInput('registry-url');
7186171857
const alwaysAuth = core.getInput('always-auth');
7186271858
if (registryUrl) {

src/main.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,16 @@ export async function run() {
4141
}
4242

4343
// Output version of node is being used
44-
let installedVersion = '';
45-
const result = await exec.exec('node', ['--version'], {
46-
ignoreReturnCode: true,
47-
silent: false,
48-
listeners: {
49-
stdout: data => {
50-
installedVersion = data.toString();
51-
}
52-
}
53-
});
54-
core.setOutput('node-version', installedVersion);
44+
try {
45+
const {stdout: installedVersion} = await exec.getExecOutput(
46+
'node',
47+
['--version'],
48+
{ignoreReturnCode: true, silent: false}
49+
);
50+
core.setOutput('node-version', installedVersion);
51+
} catch (err) {
52+
core.setOutput('node-version', '');
53+
}
5554

5655
const registryUrl: string = core.getInput('registry-url');
5756
const alwaysAuth: string = core.getInput('always-auth');

0 commit comments

Comments
 (0)