Skip to content

Commit

Permalink
add error handling, stderr output
Browse files Browse the repository at this point in the history
  • Loading branch information
Programmerino committed May 2, 2024
1 parent fa84965 commit 03abe9b
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions sky/adaptors/azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 03abe9b

Please sign in to comment.