You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

109 lines
3.9 KiB

4 years ago
  1. # Copyright 2014 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License"). You
  4. # may not use this file except in compliance with the License. A copy of
  5. # the License is located at
  6. #
  7. # http://aws.amazon.com/apache2.0/
  8. #
  9. # or in the "license" file accompanying this file. This file is
  10. # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
  11. # ANY KIND, either express or implied. See the License for the specific
  12. # language governing permissions and limitations under the License.
  13. # All exceptions in this class should subclass from Boto3Error.
  14. import botocore.exceptions
  15. # All exceptions should subclass from Boto3Error in this module.
  16. class Boto3Error(Exception):
  17. """Base class for all Boto3 errors."""
  18. class ResourceLoadException(Boto3Error):
  19. pass
  20. # NOTE: This doesn't appear to be used anywhere.
  21. # It's probably safe to remove this.
  22. class NoVersionFound(Boto3Error):
  23. pass
  24. # We're subclassing from botocore.exceptions.DataNotFoundError
  25. # to keep backwards compatibility with anyone that was catching
  26. # this low level Botocore error before this exception was
  27. # introduced in boto3.
  28. # Same thing for ResourceNotExistsError below.
  29. class UnknownAPIVersionError(Boto3Error,
  30. botocore.exceptions.DataNotFoundError):
  31. def __init__(self, service_name, bad_api_version,
  32. available_api_versions):
  33. msg = (
  34. "The '%s' resource does not an API version of: %s\n"
  35. "Valid API versions are: %s"
  36. % (service_name, bad_api_version, available_api_versions)
  37. )
  38. # Not using super because we don't want the DataNotFoundError
  39. # to be called, it has a different __init__ signature.
  40. Boto3Error.__init__(self, msg)
  41. class ResourceNotExistsError(Boto3Error,
  42. botocore.exceptions.DataNotFoundError):
  43. """Raised when you attempt to create a resource that does not exist."""
  44. def __init__(self, service_name, available_services, has_low_level_client):
  45. msg = (
  46. "The '%s' resource does not exist.\n"
  47. "The available resources are:\n"
  48. " - %s\n" % (service_name, '\n - '.join(available_services))
  49. )
  50. if has_low_level_client:
  51. msg += (
  52. "\nConsider using a boto3.client('%s') instead "
  53. "of a resource for '%s'" % (service_name, service_name))
  54. # Not using super because we don't want the DataNotFoundError
  55. # to be called, it has a different __init__ signature.
  56. Boto3Error.__init__(self, msg)
  57. class RetriesExceededError(Boto3Error):
  58. def __init__(self, last_exception, msg='Max Retries Exceeded'):
  59. super(RetriesExceededError, self).__init__(msg)
  60. self.last_exception = last_exception
  61. class S3TransferFailedError(Boto3Error):
  62. pass
  63. class S3UploadFailedError(Boto3Error):
  64. pass
  65. class DynamoDBOperationNotSupportedError(Boto3Error):
  66. """Raised for operantions that are not supported for an operand"""
  67. def __init__(self, operation, value):
  68. msg = (
  69. '%s operation cannot be applied to value %s of type %s directly. '
  70. 'Must use AttributeBase object methods (i.e. Attr().eq()). to '
  71. 'generate ConditionBase instances first.' %
  72. (operation, value, type(value)))
  73. Exception.__init__(self, msg)
  74. # FIXME: Backward compatibility
  75. DynanmoDBOperationNotSupportedError = DynamoDBOperationNotSupportedError
  76. class DynamoDBNeedsConditionError(Boto3Error):
  77. """Raised when input is not a condition"""
  78. def __init__(self, value):
  79. msg = (
  80. 'Expecting a ConditionBase object. Got %s of type %s. '
  81. 'Use AttributeBase object methods (i.e. Attr().eq()). to '
  82. 'generate ConditionBase instances.' % (value, type(value)))
  83. Exception.__init__(self, msg)
  84. class DynamoDBNeedsKeyConditionError(Boto3Error):
  85. pass