From b0adc7778bed7929f45db2f26dcb8f3ff1fc1b44 Mon Sep 17 00:00:00 2001 From: Davis Davalos-DeLosh Date: Sat, 25 May 2024 22:51:44 -0600 Subject: [PATCH] Refactor azure.py to use subprocess_utils and ux_utils for error handling and output handling --- sky/adaptors/azure.py | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/sky/adaptors/azure.py b/sky/adaptors/azure.py index ba7f9709471..8d1d66bf736 100644 --- a/sky/adaptors/azure.py +++ b/sky/adaptors/azure.py @@ -7,7 +7,8 @@ import threading from sky.adaptors import common -from sky.utils.subprocess_utils import run +from sky.utils import subprocess_utils +from sky.utils import ux_utils azure = common.LazyImport( 'azure', @@ -22,25 +23,25 @@ def _get_account(): - result = run('az account show -o json', - stdout=subprocess.PIPE, - stderr=subprocess.PIPE) + result = subprocess_utils.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.') + with ux_utils.print_exception_no_traceback(): + raise RuntimeError( + 'Failed to execute az account show -o json command. ' + f'Error: {error_message}') 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 + with ux_utils.print_exception_no_traceback(): + raise RuntimeError( + 'Failed to parse the output of az account show -o json ' + f'command. Error: {error_message}') from e def get_subscription_id() -> str: