Skip to content

Commit

Permalink
Improve not found error messages (Azure#6201)
Browse files Browse the repository at this point in the history
  • Loading branch information
djyou authored and derekbekoe committed Apr 26, 2018
1 parent 075ffb8 commit aaded6f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/command_modules/azure-cli-acr/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Release History

2.0.24
++++++
* Improve resource not found error messages.
* Improve resource creation performance and error handling.
* Improve acr login in non-standard consoles and WSL.
* Improve repository commands error messages.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,16 @@ def _arm_get_resource_by_name(cli_ctx, resource_name, resource_type):
elements = [item for item in result if item.name.lower() == resource_name.lower()]

if not elements:
raise CLIError(
"No resource with type '{}' can be found with name '{}'.".format(
resource_type, resource_name))
from azure.cli.core._profile import Profile
profile = Profile(cli_ctx=cli_ctx)
message = "The resource with name '{}' and type '{}' could not be found".format(
resource_name, resource_type)
try:
subscription = profile.get_subscription()
raise CLIError("{} in subscription '{} ({})'.".format(message, subscription['name'], subscription['id']))
except (KeyError, TypeError):
raise CLIError("{} in the current subscription.".format(message))

elif len(elements) == 1:
return elements[0]
else:
Expand Down

0 comments on commit aaded6f

Please sign in to comment.