Debian Codegraph @

boto3/exceptions.py

raw
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 # https://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
14 # All exceptions in this class should subclass from Boto3Error.
15 import botocore.exceptions
16
17
18 # All exceptions should subclass from Boto3Error in this module.
19 class Boto3Error(Exception):
20 """Base class for all Boto3 errors."""
21
22
23 class ResourceLoadException(Boto3Error):
24 pass
25
26
27 # NOTE: This doesn't appear to be used anywhere.
28 # It's probably safe to remove this.
29 class NoVersionFound(Boto3Error):
30 pass
31
32
33 # We're subclassing from botocore.exceptions.DataNotFoundError
34 # to keep backwards compatibility with anyone that was catching
35 # this low level Botocore error before this exception was
36 # introduced in boto3.
37 # Same thing for ResourceNotExistsError below.
38 class UnknownAPIVersionError(
39 Boto3Error, botocore.exceptions.DataNotFoundError
40 ):
41 def __init__(self, service_name, bad_api_version, available_api_versions):
42 msg = (
43 f"The '{service_name}' resource does not support an API version of: {bad_api_version}\n"
44 f"Valid API versions are: {available_api_versions}"
45 )
46 # Not using super because we don't want the DataNotFoundError
47 # to be called, it has a different __init__ signature.
48 Boto3Error.__init__(self, msg)
49
50
51 class ResourceNotExistsError(
52 Boto3Error, botocore.exceptions.DataNotFoundError
53 ):
54 """Raised when you attempt to create a resource that does not exist."""
55
56 def __init__(self, service_name, available_services, has_low_level_client):
57 msg = (
58 "The '{}' resource does not exist.\n"
59 "The available resources are:\n"
60 " - {}\n".format(
61 service_name, '\n - '.join(available_services)
62 )
63 )
64 if has_low_level_client:
65 msg = (
66 f"{msg}\nConsider using a boto3.client('{service_name}') "
67 f"instead of a resource for '{service_name}'"
68 )
69 # Not using super because we don't want the DataNotFoundError
70 # to be called, it has a different __init__ signature.
71 Boto3Error.__init__(self, msg)
72
73
74 class RetriesExceededError(Boto3Error):
75 def __init__(self, last_exception, msg='Max Retries Exceeded'):
76 super().__init__(msg)
77 self.last_exception = last_exception
78
79
80 class S3TransferFailedError(Boto3Error):
81 pass
82
83
84 class S3UploadFailedError(Boto3Error):
85 pass
86
87
88 class DynamoDBOperationNotSupportedError(Boto3Error):
89 """Raised for operations that are not supported for an operand."""
90
91 def __init__(self, operation, value):
92 msg = (
93 f'{operation} operation cannot be applied to value {value} of type '
94 f'{type(value)} directly. Must use AttributeBase object methods '
95 f'(i.e. Attr().eq()). to generate ConditionBase instances first.'
96 )
97 Exception.__init__(self, msg)
98
99
100 # FIXME: Backward compatibility
101 DynanmoDBOperationNotSupportedError = DynamoDBOperationNotSupportedError
102
103
104 class DynamoDBNeedsConditionError(Boto3Error):
105 """Raised when input is not a condition"""
106
107 def __init__(self, value):
108 msg = (
109 f'Expecting a ConditionBase object. Got {value} of type {type(value)}. '
110 f'Use AttributeBase object methods (i.e. Attr().eq()). to '
111 f'generate ConditionBase instances.'
112 )
113 Exception.__init__(self, msg)
114
115
116 class DynamoDBNeedsKeyConditionError(Boto3Error):
117 pass
118
119
120 class PythonDeprecationWarning(Warning):
121 """
122 Python version being used is scheduled to become unsupported
123 in an future release. See warning for specifics.
124 """
125
126 pass