-
Notifications
You must be signed in to change notification settings - Fork 3.4k
{Core} Remove the try-catch logic of CloudError in get_default_location_from_resource_group()
#20739
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
{Core} Remove the try-catch logic of CloudError in get_default_location_from_resource_group()
#20739
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -71,13 +71,13 @@ def generate_deployment_name(namespace): | |||||
| def get_default_location_from_resource_group(cmd, namespace): | ||||||
| if not namespace.location: | ||||||
| from azure.cli.core.commands.client_factory import get_mgmt_service_client | ||||||
| from msrestazure.azure_exceptions import CloudError | ||||||
| from azure.core.exceptions import HttpResponseError | ||||||
| from knack.util import CLIError | ||||||
|
|
||||||
| resource_client = get_mgmt_service_client(cmd.cli_ctx, ResourceType.MGMT_RESOURCE_RESOURCES) | ||||||
| try: | ||||||
| rg = resource_client.resource_groups.get(namespace.resource_group_name) | ||||||
| except CloudError as ex: | ||||||
| except HttpResponseError as ex: | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps we don't use try catch here to let And it works pretty well, just like what we are having right now. def get_default_location_from_resource_group(cmd, namespace):
if not namespace.location:
from azure.cli.core.commands.client_factory import get_mgmt_service_client
resource_client = get_mgmt_service_client(cmd.cli_ctx, ResourceType.MGMT_RESOURCE_RESOURCES)
# We don't use try catch here to let azure.cli.core.parser.AzCliCommandParser.validation_error
# handle exceptions, such as azure.core.exceptions.ResourceNotFoundError
rg = resource_client.resource_groups.get(namespace.resource_group_name)
namespace.location = rg.location # pylint: disable=no-member
logger.debug("using location '%s' from resource group '%s'", namespace.location, rg.name)But the side effect is that the exit code would be
If the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, makes sense~
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As we discussed offline, we first maintain the latest exit code and error throwing ways, because it seems to work well at present. So I remove the If additional information is needed to help locate related problem in the future, we can consider adding error log |
||||||
| raise CLIError('error retrieving default location: {}'.format(ex.message)) | ||||||
| namespace.location = rg.location # pylint: disable=no-member | ||||||
| logger.debug("using location '%s' from resource group '%s'", namespace.location, rg.name) | ||||||
|
|
||||||
Uh oh!
There was an error while loading. Please reload this page.