From 528b040d7eb35faac26df74f131f5b97c5fe2e33 Mon Sep 17 00:00:00 2001 From: SerVB Date: Tue, 14 Apr 2020 19:53:54 +0300 Subject: [PATCH] Fix crash when no version found --- dist/index.js | 47 +++++++++++++++++++++------------------ src/download-python.ts | 50 +++++++++++++++++++++++------------------- 2 files changed, 54 insertions(+), 43 deletions(-) diff --git a/dist/index.js b/dist/index.js index 50e0d832..b1a09b46 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1291,27 +1291,32 @@ function getVariable(variableName) { } function downloadLinuxCpython(version) { return __awaiter(this, void 0, void 0, function* () { - const home = yield getVariable('HOME'); - yield exec.exec('bash', [ - '-c', - ` - set -e # Any command which returns non-zero exit code will cause this shell script to exit immediately - set -x # Activate debugging to show execution details: all commands will be printed before execution - - sudo apt-get install build-essential checkinstall - sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev - - cd $HOME - wget https://www.python.org/ftp/python/${version}/Python-${version}.tgz - - tar -xvf Python-${version}.tgz - cd Python-${version} - ./configure - make - sudo checkinstall -y - ` - ]); - return `${home}/Python-${version}`; + try { + const home = yield getVariable('HOME'); + yield exec.exec('bash', [ + '-c', + ` + set -e # Any command which returns non-zero exit code will cause this shell script to exit immediately + set -x # Activate debugging to show execution details: all commands will be printed before execution + + sudo apt-get install build-essential checkinstall + sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev + + cd $HOME + wget https://www.python.org/ftp/python/${version}/Python-${version}.tgz + + tar -xvf Python-${version}.tgz + cd Python-${version} + ./configure + make + sudo checkinstall -y + ` + ]); + return `${home}/Python-${version}`; + } + catch (_a) { + return null; + } }); } exports.downloadLinuxCpython = downloadLinuxCpython; diff --git a/src/download-python.ts b/src/download-python.ts index 0453668a..2d363ad9 100644 --- a/src/download-python.ts +++ b/src/download-python.ts @@ -16,28 +16,34 @@ async function getVariable(variableName: string): Promise { return variableValue.trim(); } -export async function downloadLinuxCpython(version: string): Promise { - const home = await getVariable('HOME'); +export async function downloadLinuxCpython( + version: string +): Promise { + try { + const home = await getVariable('HOME'); - await exec.exec('bash', [ - '-c', - ` - set -e # Any command which returns non-zero exit code will cause this shell script to exit immediately - set -x # Activate debugging to show execution details: all commands will be printed before execution - - sudo apt-get install build-essential checkinstall - sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev + await exec.exec('bash', [ + '-c', + ` + set -e # Any command which returns non-zero exit code will cause this shell script to exit immediately + set -x # Activate debugging to show execution details: all commands will be printed before execution + + sudo apt-get install build-essential checkinstall + sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev + + cd $HOME + wget https://www.python.org/ftp/python/${version}/Python-${version}.tgz + + tar -xvf Python-${version}.tgz + cd Python-${version} + ./configure + make + sudo checkinstall -y + ` + ]); - cd $HOME - wget https://www.python.org/ftp/python/${version}/Python-${version}.tgz - - tar -xvf Python-${version}.tgz - cd Python-${version} - ./configure - make - sudo checkinstall -y - ` - ]); - - return `${home}/Python-${version}`; + return `${home}/Python-${version}`; + } catch { + return null; + } }