Skip to content
Merged
Show file tree
Hide file tree
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 Aug 19, 2020
e6d9a90
refine error message for SSLError
houk-ms Aug 19, 2020
2a6ca66
Merge branch 'dev' into new-error-schema
houk-ms Aug 20, 2020
9bd6ce7
fix test issues
houk-ms Aug 20, 2020
2a27fab
fix test issue for 2019-03-01-hybrid
houk-ms Aug 20, 2020
2d906ff
split AzCLIError and CommandRecommender into seperate files
houk-ms Aug 26, 2020
66ea104
Merge branch 'dev' into new-error-schema
houk-ms Aug 26, 2020
1fea90f
add timeout for CommandRecommender
houk-ms Aug 26, 2020
0688850
stop air-gapped from calling aladdin service
houk-ms Aug 31, 2020
4d79c49
code refining
houk-ms Aug 31, 2020
633a155
add errorType and userID in aladdin requests
houk-ms Sep 11, 2020
80601f8
fix live test
houk-ms Sep 11, 2020
ea8c67b
adjust aladdin response interface
houk-ms Sep 14, 2020
6a97d32
Update cloud.py
fengzhou-msft Sep 14, 2020
2632e68
fix messages and telemetry records for extension dynamic installation
houk-ms Sep 14, 2020
dccb8dc
Merge remote-tracking branch 'houk-ms/new-error-schema' into new-erro…
houk-ms Sep 14, 2020
d8eb0f3
code style refining
houk-ms Sep 14, 2020
ec6efb5
disable aladdin requests for testing environment
houk-ms Sep 15, 2020
d172242
code style refining
houk-ms Sep 15, 2020
36278a1
add environment variable in pipeline to diable aladdin request
houk-ms Sep 15, 2020
5110b6a
remove useless environment variables
houk-ms Sep 15, 2020
32c8e76
disable aladdin request for testing environments from cli core
houk-ms Sep 15, 2020
cbce73c
send errorneous command names to Aladdin
houk-ms Sep 15, 2020
a94c6f7
fix test parser
houk-ms Sep 15, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/azure-cli-core/azure/cli/core/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,26 @@ def show_help(self, cli_name, nouns, parser, is_group):
if not nouns:
print(UX_SURVEY_PROMPT_COLOR if self.cli_ctx.enable_color else UX_SURVEY_PROMPT)

def get_examples(self, command, parser, is_group):
"""Get examples of a certain command from the help file.
Get the text of the example, strip the newline character and
return a list of commands which start with the given command name.
"""
nouns = command.split(' ')[1:]
self.update_loaders_with_help_file_contents(nouns)

delimiters = ' '.join(nouns)
help_file = self.command_help_cls(self, delimiters, parser) if not is_group \
else self.group_help_cls(self, delimiters, parser)
help_file.load(parser)

def strip_command(command):
command = command.replace('\\\n', '')
contents = [item for item in command.split(' ') if item]
return ' '.join(contents).strip()

return [strip_command(example.command) for example in help_file.examples]

def _register_help_loaders(self):
import azure.cli.core._help_loaders as help_loaders
import inspect
Expand Down
88 changes: 88 additions & 0 deletions src/azure-cli-core/azure/cli/core/azclierror.py
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, '')
7 changes: 5 additions & 2 deletions src/azure-cli-core/azure/cli/core/cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@

CLOUD_CONFIG_FILE = os.path.join(GLOBAL_CONFIG_DIR, 'clouds.config')

# Add names of clouds that don't allow telemetry data collection here such as JEDI.
CLOUDS_FORBIDDING_TELEMETRY = []
# Add names of clouds that don't allow telemetry data collection here such as some air-gapped clouds.
CLOUDS_FORBIDDING_TELEMETRY = ['USSec', 'USNat']

# Add names of clouds that don't allow Aladdin requests for command recommendations here
CLOUDS_FORBIDDING_ALADDIN_REQUEST = ['USSec', 'USNat']


class CloudNotRegisteredException(Exception):
Expand Down
Loading