From 345643a937ea99209b6830e6a7f3ec18f6063948 Mon Sep 17 00:00:00 2001 From: MoChilia Date: Wed, 17 Jan 2024 14:46:27 +0800 Subject: [PATCH] modify error handling --- src/Cli/AzureCliLogin.ts | 3 --- src/PowerShell/AzPSUtils.ts | 3 --- src/cleanup.ts | 2 +- src/common/Utils.ts | 8 -------- 4 files changed, 1 insertion(+), 15 deletions(-) diff --git a/src/Cli/AzureCliLogin.ts b/src/Cli/AzureCliLogin.ts index fc67fbff..ec557fe6 100644 --- a/src/Cli/AzureCliLogin.ts +++ b/src/Cli/AzureCliLogin.ts @@ -17,9 +17,6 @@ export class AzureCliLogin { async login() { core.info(`Running Azure CLI Login.`); this.azPath = await io.which("az", true); - if (!this.azPath) { - throw new Error("Azure CLI is not found in the runner."); - } core.debug(`Azure CLI path: ${this.azPath}`); let output: string = ""; diff --git a/src/PowerShell/AzPSUtils.ts b/src/PowerShell/AzPSUtils.ts index b9f37884..4b287cfd 100644 --- a/src/PowerShell/AzPSUtils.ts +++ b/src/PowerShell/AzPSUtils.ts @@ -71,9 +71,6 @@ export class AzPSUtils { }; let psPath: string = await io.which(AzPSConstants.PowerShell_CmdName, true); - if (!psPath) { - throw new Error("PowerShell is not found in the runner."); - } await exec.exec(`"${psPath}"`, ["-Command", psScript], options) if (commandStdErr) { throw new Error('Azure PowerShell login failed with errors.'); diff --git a/src/cleanup.ts b/src/cleanup.ts index d3182263..d307920d 100644 --- a/src/cleanup.ts +++ b/src/cleanup.ts @@ -10,7 +10,7 @@ async function cleanup() { } } catch (error) { - core.setFailed(`Login cleanup failed with ${error}. Make sure 'az' is installed on the runner. If 'enable-AzPSSession' is true, make sure 'pwsh' is installed on the runner together with Azure PowerShell module.`); + core.warning(`Login cleanup failed with ${error}. Cleanup will be skipped.`); core.debug(error.stack); } } diff --git a/src/common/Utils.ts b/src/common/Utils.ts index adb96d3b..b8a089d2 100644 --- a/src/common/Utils.ts +++ b/src/common/Utils.ts @@ -13,10 +13,6 @@ export function setUserAgent(): void { export async function cleanupAzCLIAccounts(): Promise { let azPath = await io.which("az", true); - if (!azPath) { - core.warning("Azure CLI is not found in the runner."); - return; - } core.debug(`Azure CLI path: ${azPath}`); core.info("Clearing azure cli accounts from the local cache."); await exec.exec(`"${azPath}"`, ["account", "clear"]); @@ -24,10 +20,6 @@ export async function cleanupAzCLIAccounts(): Promise { export async function cleanupAzPSAccounts(): Promise { let psPath: string = await io.which(AzPSConstants.PowerShell_CmdName, true); - if (!psPath) { - core.warning("PowerShell is not found in the runner."); - return; - } core.debug(`PowerShell path: ${psPath}`); core.debug("Importing Azure PowerShell module."); AzPSUtils.setPSModulePathForGitHubRunner();