Skip to content

Conversation

@houk-ms
Copy link
Contributor

@houk-ms houk-ms commented Sep 27, 2020

Description

This PR provides

  • New error types for error improvement. A series of error classes are defined to replace the original enumerated error types.
  • Adjustments for exception handler in CLI core. The original raw exceptions from different sources are wrapped by the new defiined error types.

Base class: AzCLIError
Main-categories: UserFault, ClientError, ServiceError
Sub-categories:

# Command related error types
class CommandNotFoundError(UserFault):
    """ Command is misspelled or not recognized by AzureCLI. """
    pass


# Argument related error types
class UnrecognizedArgumentError(UserFault):
    """ Argument is misspelled or not recognized by AzureCLI. """
    pass


class RequiredArgumentMissingError(UserFault):
    """ Required argument is not specified. """
    pass


class ConflictArgumentError(UserFault):
    """ Arguments can not be specfied together. """
    pass


class InvalidArgumentValueError(UserFault):
    """ Argument value is not valid. """
    pass


class ArgumentParseError(UserFault):
    """ Fallback of the argument parsing related errors.
    Use this error only when the argument related errors
    can not be classified into the above error types. """
    pass


# Response related error types
class BadRequestError(UserFault):
    """ Bad request from client: 400 error """
    pass


class UnauthorizedError(UserFault):
    """ Unauthorized request: 401 error """


class ForbiddenError(UserFault):
    """ Service refuse to response: 403 error """


class ResourceNotFoundError(UserFault):
    """ Can not find Azure resources: 404 error """
    pass


class AzureInternalError(ServiceError):
    """ Azure service internal error: 5xx error """
    pass


class AzureResponseError(UserFault):
    """ Fallback of the response related errors.
    Use this error only when the response related errors
    can not be classified into the above error types. """


# Request related error types
class AzureConnectionError(UserFault):
    """ Connection issues like connection timeout, aborted or broken. """
    pass


class ClientRequestError(UserFault):
    """ Fallback of the request related errors.
    Error occurs while attempting to make a request to the service. No request is sent.
    """


# Validation related error types
class ValidationError(UserFault):
    """ Fallback of the errors in validation functions.
    Use this error in validation functions only when the error can not be
    classified into the Argument, Request and Response related error types. """
    pass


# CLI internal error type
class CLIInternalError(ClientError):
    """ Azure CLI internal error """
    pass


# Keyboard interrupt error type
class ManualInterrupt(UserFault):
    """ Keyboard interrupt. """
    pass

@yungezz yungezz added this to the S176 milestone Sep 28, 2020
@houk-ms
Copy link
Contributor Author

houk-ms commented Sep 28, 2020

Another problem in exception_handler:

We are extracting error messages from the response instead of the error's formatted error_msg for AzureError, CloudError and HttpResponseError. Pro is we can show more useful info from response, con is hard to maintain and have to deal with all knids of
abnormal response cases. Here's an example the useful message is suppressed #15314

# region: Second Layer
# Main categories of the AzureCLI error types, used for Telemetry alalysis
# DO NOT raise the error classes here directly in your codes.
class UserFault(AzCLIError):
Copy link
Member

Choose a reason for hiding this comment

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

good point from @qwordy . how about _UserFault with _ prefix to hint user not to use those?

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

I don't it is revolved. Reopen the conversation.

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.

7 participants