-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[Core] New error output #16257
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
[Core] New error output #16257
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
2d016aa
initial version for new error output
houk-ms 6caf27d
Merge branch 'dev' into remove-error-type-prefix
houk-ms 74e9297
apply style in recommendations
houk-ms 890072f
sort the recommendations
houk-ms 7f3aad1
support config to disable error recommendations
houk-ms 98595c9
command recommender refactoring
houk-ms 75ae600
code style refining
houk-ms 713f62d
merge dev branch
houk-ms 3e58891
code refining
houk-ms 62e85fd
resolve merge conflicts
houk-ms 5e04dad
merge with dev
houk-ms 0680f50
use core.error_recommendation=on/off as error recommmendation switch
houk-ms 6db67e7
resolve conflicts
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 |
|---|---|---|
|
|
@@ -29,38 +29,58 @@ def __init__(self, error_msg, recommendation=None): | |
| # error message | ||
| self.error_msg = error_msg | ||
|
|
||
| # set recommendations to fix the error if the message is not actionable, | ||
| # they will be printed to users after the error message, one recommendation per line | ||
| # manual recommendations provided based on developers' knowledge | ||
| self.recommendations = [] | ||
| self.set_recommendation(recommendation) | ||
|
|
||
| # AI recommendations provided by Aladdin service, with tuple form: (recommendation, description) | ||
| self.aladdin_recommendations = [] | ||
|
|
||
| # exception trace for the error | ||
| self.exception_trace = None | ||
| super().__init__(error_msg) | ||
|
|
||
| def set_recommendation(self, recommendation): | ||
| """" Set manual recommendations for the error. | ||
| Command module or extension authors could call this method to provide recommendations, | ||
| the recommendations will be printed after the error message, one recommendation per line | ||
| """ | ||
| if isinstance(recommendation, str): | ||
| self.recommendations.append(recommendation) | ||
| elif isinstance(recommendation, list): | ||
| self.recommendations.extend(recommendation) | ||
|
|
||
| def set_aladdin_recommendation(self, recommendations): | ||
| """ Set aladdin recommendations for the error. | ||
| One item should be a tuple with the form: (recommendation, description) | ||
| """ | ||
| self.aladdin_recommendations.extend(recommendations) | ||
|
|
||
| def set_exception_trace(self, exception_trace): | ||
| self.exception_trace = exception_trace | ||
|
|
||
| def print_error(self): | ||
| from azure.cli.core.azlogging import CommandLoggerContext | ||
| from azure.cli.core.style import print_styled_text | ||
| with CommandLoggerContext(logger): | ||
| # print error type and error message | ||
| message = '{}: {}'.format(self.__class__.__name__, self.error_msg) | ||
| logger.error(message) | ||
| # print error message | ||
| logger.error(self.error_msg) | ||
|
|
||
| # print exception trace if there is | ||
| if self.exception_trace: | ||
| logger.exception(self.exception_trace) | ||
|
|
||
| # print recommendations to action | ||
| if self.recommendations: | ||
| for recommendation in self.recommendations: | ||
| print(recommendation, file=sys.stderr) | ||
|
|
||
| if self.aladdin_recommendations: | ||
| print('\nTRY THIS:', file=sys.stderr) | ||
| for recommendation, description in self.aladdin_recommendations: | ||
| print_styled_text(recommendation, file=sys.stderr) | ||
|
Member
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.
|
||
| print_styled_text(description, file=sys.stderr) | ||
|
|
||
| def send_telemetry(self): | ||
| telemetry.set_error_type(self.__class__.__name__) | ||
| # endregion | ||
|
|
@@ -101,15 +121,6 @@ def send_telemetry(self): | |
| super().send_telemetry() | ||
| telemetry.set_failure(self.error_msg) | ||
|
|
||
| def print_error(self): | ||
| from azure.cli.core.azlogging import CommandLoggerContext | ||
| with CommandLoggerContext(logger): | ||
| # print only error message (no error type) | ||
| logger.error(self.error_msg) | ||
| # print recommendations to action | ||
| if self.recommendations: | ||
| for recommendation in self.recommendations: | ||
| print(recommendation, file=sys.stderr) | ||
| # endregion | ||
|
|
||
|
|
||
|
|
@@ -233,15 +244,7 @@ class UnclassifiedUserFault(UserFault): | |
| Avoid using this class unless the error can not be classified into | ||
| the UserFault related specific error types. | ||
| """ | ||
| def print_error(self): | ||
| from azure.cli.core.azlogging import CommandLoggerContext | ||
| with CommandLoggerContext(logger): | ||
| # print only error message (no error type) | ||
| logger.error(self.error_msg) | ||
| # print recommendations to action | ||
| if self.recommendations: | ||
| for recommendation in self.recommendations: | ||
| print(recommendation, file=sys.stderr) | ||
| pass | ||
|
|
||
|
|
||
| # CLI internal error type | ||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can use
print_styled_text("\nTRY THIS:")orprint_styled_text((Style.PRIMARY, "\nTRY THIS:"))once #16258 is merged.