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 449385c
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions sky/adaptors/azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,21 @@


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}\nCommand Error: {error_message}")


def get_subscription_id() -> str:
Expand Down

0 comments on commit 449385c

Please sign in to comment.