From 45a40e9d9520c583bda2fa05122eb802afce052d Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Wed, 31 Jan 2024 23:43:42 -0800 Subject: [PATCH] fix: throw an error if could not find the python binary --- src/python/python.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/python/python.ts b/src/python/python.ts index 4a4bf03d..3e0751c4 100644 --- a/src/python/python.ts +++ b/src/python/python.ts @@ -89,7 +89,10 @@ async function findOrSetupPython(version: string, setupDir: string, arch: string const { setupActionsPython } = await import("./actions_python") await setupActionsPython(version, setupDir, arch) - foundPython = (await findPython(setupDir))! + foundPython = await findPython(setupDir) + if (foundPython === undefined) { + throw new Error("Python binary could not be found") + } const binDir = dirname(foundPython) installInfo = { bin: foundPython, installDir: binDir, binDir } } catch (err) { @@ -103,7 +106,10 @@ async function findOrSetupPython(version: string, setupDir: string, arch: string } if (foundPython === undefined || installInfo.bin === undefined) { - foundPython = (await findPython(setupDir))! + foundPython = await findPython(setupDir) + if (foundPython === undefined) { + throw new Error("Python binary could not be found") + } installInfo.bin = foundPython } @@ -120,7 +126,10 @@ async function setupPythonSystem(setupDir: string, version: string) { await setupChocoPack("python3", version) } // Adding the bin dir to the path - const bin = (await findPython(setupDir))! + const bin = await findPython(setupDir) + if (bin === undefined) { + throw new Error("Python binary could not be found") + } const binDir = dirname(bin) /** The directory which the tool is installed to */ await addPath(binDir)