Skip to content

Commit

Permalink
Refactor azure.py to use subprocess_utils and ux_utils for error hand…
Browse files Browse the repository at this point in the history
…ling and output handling
  • Loading branch information
Programmerino committed May 26, 2024
1 parent 03abe9b commit b0adc77
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions sky/adaptors/azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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:
Expand Down

0 comments on commit b0adc77

Please sign in to comment.