From 03abe9b969088a11fc9fa2c8f8ce13eac3e04acf Mon Sep 17 00:00:00 2001 From: Davis Davalos-DeLosh Date: Thu, 2 May 2024 13:37:44 -0600 Subject: [PATCH] add error handling, stderr output --- sky/adaptors/azure.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/sky/adaptors/azure.py b/sky/adaptors/azure.py index c4324f499d8..ba7f9709471 100644 --- a/sky/adaptors/azure.py +++ b/sky/adaptors/azure.py @@ -22,10 +22,25 @@ def _get_account(): - return json.loads( - run('az account show -o json', - stdout=subprocess.PIPE, - stderr=subprocess.DEVNULL).stdout.decode()) + result = run('az account show -o json', + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + + if result.returncode != 0: + error_message = result.stderr.decode() + print(f'Error executing command: {error_message}') + raise RuntimeError( + 'Failed to execute az account show -o json command.') + + try: + return json.loads(result.stdout.decode()) + except json.JSONDecodeError as e: + error_message = result.stderr.decode() + print(f'JSON parsing error: {e.msg}') + raise RuntimeError( + f'Failed to parse JSON output. Error: {e.msg}\n' + f'Command Error: {error_message}' + ) from e def get_subscription_id() -> str: