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


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 ac81b26

Please sign in to comment.