Skip to content

Commit 78adee2

Browse files
committed
better exception handling
1 parent 3116da7 commit 78adee2

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

tools/get_keys.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ async def get_az_cli_logged_in_info(print_info: bool = True) -> AzCliLoggedInInf
7979

8080
return info
8181
except subprocess.CalledProcessError:
82-
raise Exception("User not logged in to Azure CLI. Run 'az login'.")
82+
raise RuntimeError("User not logged in to Azure CLI. Run 'az login'.")
8383
except FileNotFoundError:
84-
raise Exception(
84+
raise RuntimeError(
8585
"Azure CLI is not installed. Install it and run 'az login' before running this tool."
8686
)
8787

@@ -154,7 +154,7 @@ async def elevate(self, options: Dict):
154154
)
155155
)
156156
except Exception as e:
157-
print(e)
157+
print(repr(e))
158158
print(
159159
colored(f"Unable to elevate for role {options['roleName']}.", Fore.RED)
160160
)
@@ -199,7 +199,7 @@ async def get_role_definition_id(
199199
Fore.RED,
200200
)
201201
)
202-
raise Exception(f"Unable to find the role '{role_name}'.")
202+
raise RuntimeError(f"Unable to find the role '{role_name}'.")
203203

204204
async def get_principal_id(self, continue_on_failure: bool = False) -> str:
205205
"""Get the principal ID of the current user."""
@@ -213,7 +213,7 @@ async def get_principal_id(self, continue_on_failure: bool = False) -> str:
213213
account_details = json.loads(result.stdout)
214214
return account_details["id"]
215215
except Exception as e:
216-
print(e)
216+
print(repr(e))
217217
if not continue_on_failure:
218218
print(
219219
colored(
@@ -223,7 +223,7 @@ async def get_principal_id(self, continue_on_failure: bool = False) -> str:
223223
)
224224
sys.exit(12)
225225
else:
226-
raise Exception("Unable to get principal id of the current user.")
226+
raise RuntimeError("Unable to get principal id of the current user.")
227227

228228

229229
class AzCliKeyVaultClient:
@@ -604,7 +604,7 @@ async def pull_secrets():
604604
)
605605

606606
if shared_updated is None and private_updated is None:
607-
raise Exception("No secrets found in key vaults.")
607+
raise RuntimeError("No secrets found in key vaults.")
608608

609609
updated = (shared_updated or 0) + (private_updated or 0)
610610

0 commit comments

Comments
 (0)