Skip to content

Commit

Permalink
Remove unnecessary nesting of try blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
JimMadge committed Oct 23, 2023
1 parent a6580e6 commit 39d6287
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions data_safe_haven/external/api/azure_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,22 @@ def account(self) -> AzureCliAccount:
stderr=subprocess.PIPE,
encoding="utf8",
)

try:
result_dict = json.loads(result)
except json.JSONDecodeError as exc:
msg = f"Unable to parse Azure CLI output as JSON.\n{result}"
raise DataSafeHavenAzureError(msg) from exc

self._account = AzureCliAccount(
name=result_dict.get("user").get("name"),
id_=result_dict.get("id"),
tenant_id=result_dict.get("tenantId"),
)

except subprocess.CalledProcessError as exc:
msg = f"Error getting account information from Azure CLI.\n{exc.stderr}"
raise DataSafeHavenAzureError(msg) from exc

try:
result_dict = json.loads(result)
except json.JSONDecodeError as exc:
msg = f"Unable to parse Azure CLI output as JSON.\n{result}"
raise DataSafeHavenAzureError(msg) from exc

self._account = AzureCliAccount(
name=result_dict.get("user").get("name"),
id_=result_dict.get("id"),
tenant_id=result_dict.get("tenantId"),
)

return self._account

def confirm(self) -> None:
Expand Down

0 comments on commit 39d6287

Please sign in to comment.