Skip to content

{Error Improvement} Catch and categorize HttpError in core exception handler#15613

Merged
houk-ms merged 2 commits intoAzure:devfrom
houk-ms:HTTPError
Oct 22, 2020
Merged

{Error Improvement} Catch and categorize HttpError in core exception handler#15613
houk-ms merged 2 commits intoAzure:devfrom
houk-ms:HTTPError

Conversation

@houk-ms
Copy link
Contributor

@houk-ms houk-ms commented Oct 22, 2020

Description

HTTPErrors are widely raised in different command groups, while they are not caught in core exception handler. Previously, CLI would crash and users would get the raw traces when these error happen.

This PR supports

  • catching the HTTPErrors in core exception handler.
  • categorizing them into the new defined error types.

Here is a table showing the uncaught HTTPError count in AzureCLI@2.12.0 in last month.

CommandGroup HTTPError Count
NETWORK 1392
DLS 208
AD 123
VM 77
AKS 51
LOGIN 41
CONTAINER 36
GROUP 35
PROVIDER 31
COSMOSDB 27
DEPLOYMENT 27
ROLE 26
ACCOUNT 20
RESOURCE 11
STORAGE 11
DT 9
TAG 9
KEYVAULT 8
IMAGE 7
ARO 4
POLICY 4
SQL 4
VMSS 4
BACKUP 3
SIG 3
WEBAPP 3
DISK 2
FUNCTIONAPP 2
IOT 2
ACR 1
FUSION 1

Testing Guide

You can test the case by raising an HTTPError manually in your codes, for example

Previously, when the HTTPError was not caught, CLI just crashed.

CLIInternalError: The command failed with an unexpected error. Here is the traceback:
Traceback (most recent call last):
  File "C:\Users\houk\Desktop\msws\env_new\lib\site-packages\knack\cli.py", line 215, in invoke
    cmd_result = self.invocation.execute(args)
  File "c:\users\houk\desktop\msws\azure-cli\src\azure-cli-core\azure\cli\core\commands\__init__.py", line 654, in execute
    raise ex
  File "c:\users\houk\desktop\msws\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 "c:\users\houk\desktop\msws\azure-cli\src\azure-cli-core\azure\cli\core\commands\__init__.py", line 711, in _run_job
    six.reraise(*sys.exc_info())
  File "C:\Users\houk\Desktop\msws\env_new\lib\site-packages\six.py", line 703, in reraise
    raise value
  File "c:\users\houk\desktop\msws\azure-cli\src\azure-cli-core\azure\cli\core\commands\__init__.py", line 688, in _run_job
    result = cmd_copy(params)
  File "c:\users\houk\desktop\msws\azure-cli\src\azure-cli-core\azure\cli\core\commands\__init__.py", line 325, in __call__
    return self.handler(*args, **kwargs)
  File "c:\users\houk\desktop\msws\azure-cli\src\azure-cli-core\azure\cli\core\__init__.py", line 784, in default_command_handler
    return op(**command_args)
  File "c:\users\houk\desktop\msws\azure-cli\src\azure-cli\azure\cli\command_modules\vm\custom.py", line 581, in list_snapshots
    raise err
requests.exceptions.HTTPError: [Errno 400] test_url: 'test_err_message'
To open an issue, please run: 'az feedback'

Now,

BadRequestError: [Errno 400] test_url: 'test_err_message'

@houk-ms
Copy link
Contributor Author

houk-ms commented Oct 22, 2020

Previously, these errors make CLI crashed and were categorized into ClientError. Now they are categorized into UserFault or ServiceError according to the status code.

@houk-ms houk-ms merged commit 537acc6 into Azure:dev Oct 22, 2020
@houk-ms
Copy link
Contributor Author

houk-ms commented Oct 26, 2020

#15314

@houk-ms
Copy link
Contributor Author

houk-ms commented Oct 26, 2020

#14979

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants