From d81b44b11248c354f2ce14d79abf48ac240b0fe9 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Sat, 18 Sep 2021 10:38:48 -0500 Subject: [PATCH] fix: try-catch adding path using system --- src/utils/path/addPath.ts | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/src/utils/path/addPath.ts b/src/utils/path/addPath.ts index 0d1fb760..f0df6982 100644 --- a/src/utils/path/addPath.ts +++ b/src/utils/path/addPath.ts @@ -8,23 +8,28 @@ export async function addPath(path: string) { try { ghAddPath(path) } catch (err) { - core.error(err as Error) - switch (process.platform) { - case "win32": { - await execa(`setx PATH=${path};%PATH%`) - break - } - case "linux": - case "darwin": { - await execa.command(`echo "export PATH=${path}:$PATH" >> ~/.profile`) - await execa.command(`source ~/.profile`) - core.info(`${path} was added to ~/.profile`) - break - } - default: { - core.error(`Failed to add ${path} to the percistent PATH. You should add it manually.`) - process.env.PATH = `${path}${delimiter}${process.env.PATH}` + try { + core.error(err as Error) + switch (process.platform) { + case "win32": { + await execa(`setx PATH=${path};%PATH%`) + return + } + case "linux": + case "darwin": { + await execa.command(`echo "export PATH=${path}:$PATH" >> ~/.profile`) + await execa.command(`source ~/.profile`) + core.info(`${path} was added to ~/.profile`) + return + } + default: { + // fall through shell path modification + } } + } catch (err2) { + core.error(err2 as Error) } + core.error(`Failed to add ${path} to the percistent PATH. You should add it manually.`) + process.env.PATH = `${path}${delimiter}${process.env.PATH}` } }