Skip to content

{Core} Print traceback to debug log when handle_exception is called#14588

Merged
jiasli merged 1 commit intoAzure:devfrom
jiasli:trackback
Sep 9, 2020
Merged

{Core} Print traceback to debug log when handle_exception is called#14588
jiasli merged 1 commit intoAzure:devfrom
jiasli:trackback

Conversation

@jiasli
Copy link
Member

@jiasli jiasli commented Jul 30, 2020

Description

Print traceback to debug log when azure.cli.core.util.handle_exception is called. This can help identify where the exception is generated and thrown.

Testing Guide

Notice the location westu is wrong (should be westus):

> az group create -n rg1 -l westu --debug
...
azure.cli.core.util.handle_exception is called with an exception:
Traceback (most recent call last):
  File "D:\cli\env38\lib\site-packages\knack\cli.py", line 215, in invoke
    cmd_result = self.invocation.execute(args)
  File "d:\cli\azure-cli\src\azure-cli-core\azure\cli\core\commands\__init__.py", line 654, in execute
    raise ex
  File "d:\cli\azure-cli\src\azure-cli-core\azure\cli\core\commands\__init__.py", line 718, in _run_jobs_serially
    results.append(self._run_job(expanded_arg, cmd_copy))
  File "d:\cli\azure-cli\src\azure-cli-core\azure\cli\core\commands\__init__.py", line 711, in _run_job
    six.reraise(*sys.exc_info())
  File "D:\cli\env38\lib\site-packages\six.py", line 703, in reraise
    raise value
  File "d:\cli\azure-cli\src\azure-cli-core\azure\cli\core\commands\__init__.py", line 688, in _run_job
    result = cmd_copy(params)
  File "d:\cli\azure-cli\src\azure-cli-core\azure\cli\core\commands\__init__.py", line 325, in __call__
    return self.handler(*args, **kwargs)
  File "d:\cli\azure-cli\src\azure-cli-core\azure\cli\core\__init__.py", line 776, in default_command_handler
    return op(**command_args)
  File "d:\cli\azure-cli\src\azure-cli\azure\cli\command_modules\resource\custom.py", line 1082, in create_resource_group
    return rcf.resource_groups.create_or_update(rg_name, parameters)
  File "d:\cli\env38\lib\site-packages\azure\mgmt\resource\resources\v2020_06_01\operations\_resource_groups_operations.py", line 154, in create_or_update
    raise exp
msrestazure.azure_exceptions.CloudError: Azure Error: LocationNotAvailableForResourceGroup
Message: The provided location 'westu' is not available for resource group. List of available regions is 'centralus,eastasia,southeastasia,eastus,eastus2,westus,westus2,northcentralus,southcentralus,westcentralus,northeurope,westeurope,japaneast,japanwest,brazilsouth,australiasoutheast,australiaeast,westindia,southindia,centralindia,canadacentral,canadaeast,uksouth,ukwest,koreacentral,koreasouth,francecentral,southafricanorth,uaenorth,australiacentral,switzerlandnorth,germanywestcentral,norwayeast,eastus2euap,centraluseuap'.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capture requests.exceptions.SSLError which is generated by directly calling requests's methods.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will msrest capture SSLError?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. It will be thrown as ClientRequestError.

image

@yonzhan yonzhan added this to the S174 milestone Jul 30, 2020
@yonzhan
Copy link
Collaborator

yonzhan commented Jul 30, 2020

Core

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We still lack a good way to manage short links. Perhaps we need a meeting to discuss about how to manage them.

Copy link
Member

@jsntcy jsntcy Aug 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any security concern to expose the whole traceback to users?
Usually we can store trackback in our telemetry, but just show meaningful messages to users.

Copy link
Member Author

@jiasli jiasli Aug 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. The traceback contains no sensitive information, but only the code flow. The value of parameters are not displayed.
  2. The traceback only appears in the --debug log and is not sent anywhere. If the user wants to share it, he/she can filter it first.
  3. On the contrary, using client telemetry would expose more security concern as the traceback is sent over the network if telemetry is turned on.
  4. Using client telemetry would require us to identify the specific command execution from other millions of command executions.
  5. Anyway, the client telemetry doesn't support sending debug log right now.

@yonzhan yonzhan modified the milestones: S174, S175 - For Ignite Aug 22, 2020
@jiasli jiasli requested a review from qwordy September 9, 2020 03:28

logger.debug("azure.cli.core.util.handle_exception is called with an exception:")
# Print the traceback and exception message
logger.debug(traceback.format_exc())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make sure the trace is of ex? ex is not used.

Copy link
Member Author

@jiasli jiasli Sep 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

format_exc prints the last exception (represented by sys.exc_info()), and when handle_exception is called, sys.exc_info() corresponds to ex.

@jiasli jiasli merged commit 02d66de into Azure:dev Sep 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants