-
Notifications
You must be signed in to change notification settings - Fork 3.4k
[Core] Error message improvement #14855
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
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
7e086d8
draft for new error schema
houk-ms e6d9a90
refine error message for SSLError
houk-ms 2a6ca66
Merge branch 'dev' into new-error-schema
houk-ms 9bd6ce7
fix test issues
houk-ms 2a27fab
fix test issue for 2019-03-01-hybrid
houk-ms 2d906ff
split AzCLIError and CommandRecommender into seperate files
houk-ms 66ea104
Merge branch 'dev' into new-error-schema
houk-ms 1fea90f
add timeout for CommandRecommender
houk-ms 0688850
stop air-gapped from calling aladdin service
houk-ms 4d79c49
code refining
houk-ms 633a155
add errorType and userID in aladdin requests
houk-ms 80601f8
fix live test
houk-ms ea8c67b
adjust aladdin response interface
houk-ms 6a97d32
Update cloud.py
fengzhou-msft 2632e68
fix messages and telemetry records for extension dynamic installation
houk-ms dccb8dc
Merge remote-tracking branch 'houk-ms/new-error-schema' into new-erro…
houk-ms d8eb0f3
code style refining
houk-ms ec6efb5
disable aladdin requests for testing environment
houk-ms d172242
code style refining
houk-ms 36278a1
add environment variable in pipeline to diable aladdin request
houk-ms 5110b6a
remove useless environment variables
houk-ms 32c8e76
disable aladdin request for testing environments from cli core
houk-ms cbce73c
send errorneous command names to Aladdin
houk-ms a94c6f7
fix test parser
houk-ms File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| # -------------------------------------------------------------------------------------------- | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. See License.txt in the project root for license information. | ||
| # -------------------------------------------------------------------------------------------- | ||
|
|
||
| import sys | ||
| from enum import Enum | ||
|
|
||
| from knack.util import CLIError | ||
| from knack.log import get_logger | ||
|
|
||
| logger = get_logger(__name__) | ||
|
|
||
|
|
||
| class AzCLIErrorType(Enum): | ||
| """ AzureCLI error types """ | ||
|
|
||
| # userfaults | ||
| CommandNotFoundError = 'CommandNotFoundError' | ||
| ArgumentParseError = 'ArgumentParseError' | ||
| ValidationError = 'ValidationError' | ||
| ManualInterrupt = 'ManualInterrupt' | ||
| # service side error | ||
| ServiceError = 'ServiceError' | ||
| # client side error | ||
| ClientError = 'ClientError' | ||
| # unexpected error | ||
| UnexpectedError = 'UnexpectedError' | ||
|
|
||
|
|
||
| class AzCLIError(CLIError): | ||
| """ AzureCLI error definition """ | ||
|
|
||
| def __init__(self, error_type, error_msg, raw_exception=None, command=None): | ||
| """ | ||
| :param error_type: The name of the AzureCLI error type. | ||
| :type error_type: azure.cli.core.util.AzCLIErrorType | ||
| :param error_msg: The error message detail. | ||
| :type error_msg: str | ||
| :param raw_exception: The raw exception. | ||
| :type raw_exception: Exception | ||
| :param command: The command which brings the error. | ||
| :type command: str | ||
| :param recommendations: The recommendations to resolve the error. | ||
| :type recommendations: list | ||
| """ | ||
| self.error_type = error_type | ||
| self.error_msg = error_msg | ||
| self.raw_exception = raw_exception | ||
| self.command = command | ||
| self.recommendations = [] | ||
| super().__init__(error_msg) | ||
|
|
||
| def set_recommendation(self, recommendation): | ||
| self.recommendations.append(recommendation) | ||
|
|
||
| def set_raw_exception(self, raw_exception): | ||
| self.raw_exception = raw_exception | ||
|
|
||
| def print_error(self): | ||
| from azure.cli.core.azlogging import CommandLoggerContext | ||
| with CommandLoggerContext(logger): | ||
| message = '{}: {}'.format(self.error_type.value, self.error_msg) | ||
| logger.error(message) | ||
| if self.raw_exception: | ||
| logger.exception(self.raw_exception) | ||
| if self.recommendations: | ||
| for recommendation in self.recommendations: | ||
| print(recommendation, file=sys.stderr) | ||
|
|
||
| def send_telemetry(self): | ||
| import azure.cli.core.telemetry as telemetry | ||
| telemetry.set_error_type(self.error_type.value) | ||
|
|
||
| # For userfaults | ||
| if self.error_type in [AzCLIErrorType.CommandNotFoundError, | ||
| AzCLIErrorType.ArgumentParseError, | ||
| AzCLIErrorType.ValidationError, | ||
| AzCLIErrorType.ManualInterrupt]: | ||
| telemetry.set_user_fault(self.error_msg) | ||
|
|
||
| # For failures: service side error, client side error, unexpected error | ||
| else: | ||
| telemetry.set_failure(self.error_msg) | ||
|
|
||
| # For unexpected error | ||
| if self.raw_exception: | ||
| telemetry.set_exception(self.raw_exception, '') | ||
houk-ms marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.