mirror of
				https://github.com/actions/setup-node.git
				synced 2025-11-04 13:29:12 +08:00 
			
		
		
		
	add try catch
This commit is contained in:
		
							
								
								
									
										18
									
								
								dist/setup/index.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										18
									
								
								dist/setup/index.js
									
									
									
									
										vendored
									
									
								
							@@ -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) {
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										21
									
								
								src/main.ts
									
									
									
									
									
								
							
							
						
						
									
										21
									
								
								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');
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user