Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
errors.py195 linesDownload Raw Back to chromadb
1from abc import abstractmethod
2from typing import Dict, Optional, Type
3from overrides import overrides, EnforceOverrides
4
5
6class ChromaError(Exception, EnforceOverrides):
7    trace_id: Optional[str] = None
8
9    def code(self) -> int:
10        """Return an appropriate HTTP response code for this error"""
11        return 400  # Bad Request
12
13    def message(self) -> str:
14        return ", ".join(self.args)
15
16    @classmethod
17    @abstractmethod
18    def name(cls) -> str:
19        """Return the error name"""
20        pass
21
22
23class InvalidDimensionException(ChromaError):
24    @classmethod
25    @overrides
26    def name(cls) -> str:
27        return "InvalidDimension"
28
29
30class IDAlreadyExistsError(ChromaError):
31    @overrides
32    def code(self) -> int:
33        return 409  # Conflict
34
35    @classmethod
36    @overrides
37    def name(cls) -> str:
38        return "IDAlreadyExists"
39
40
41class ChromaAuthError(ChromaError):
42    @overrides
43    def code(self) -> int:
44        return 403
45
46    @classmethod
47    @overrides
48    def name(cls) -> str:
49        return "AuthError"
50
51    @overrides
52    def message(self) -> str:
53        return "Forbidden"
54
55
56class DuplicateIDError(ChromaError):
57    @classmethod
58    @overrides
59    def name(cls) -> str:
60        return "DuplicateID"
61
62
63class InvalidArgumentError(ChromaError):
64    @overrides
65    def code(self) -> int:
66        return 400
67
68    @classmethod
69    @overrides
70    def name(cls) -> str:
71        return "InvalidArgument"
72
73
74class InvalidUUIDError(ChromaError):
75    @classmethod
76    @overrides
77    def name(cls) -> str:
78        return "InvalidUUID"
79
80
81class InvalidHTTPVersion(ChromaError):
82    @classmethod
83    @overrides
84    def name(cls) -> str:
85        return "InvalidHTTPVersion"
86
87
88class AuthorizationError(ChromaError):
89    @overrides
90    def code(self) -> int:
91        return 401
92
93    @classmethod
94    @overrides
95    def name(cls) -> str:
96        return "AuthorizationError"
97
98
99class NotFoundError(ChromaError):
100    @overrides
101    def code(self) -> int:
102        return 404
103
104    @classmethod
105    @overrides
106    def name(cls) -> str:
107        return "NotFoundError"
108
109
110class UniqueConstraintError(ChromaError):
111    @overrides
112    def code(self) -> int:
113        return 409
114
115    @classmethod
116    @overrides
117    def name(cls) -> str:
118        return "UniqueConstraintError"
119
120
121class BatchSizeExceededError(ChromaError):
122    @overrides
123    def code(self) -> int:
124        return 413
125
126    @classmethod
127    @overrides
128    def name(cls) -> str:
129        return "BatchSizeExceededError"
130
131
132class VersionMismatchError(ChromaError):
133    @overrides
134    def code(self) -> int:
135        return 500
136
137    @classmethod
138    @overrides
139    def name(cls) -> str:
140        return "VersionMismatchError"
141
142
143class InternalError(ChromaError):
144    @overrides
145    def code(self) -> int:
146        return 500
147
148    @classmethod
149    @overrides
150    def name(cls) -> str:
151        return "InternalError"
152
153
154class RateLimitError(ChromaError):
155    @overrides
156    def code(self) -> int:
157        return 429
158
159    @classmethod
160    @overrides
161    def name(cls) -> str:
162        return "RateLimitError"
163
164
165class QuotaError(ChromaError):
166    @overrides
167    def code(self) -> int:
168        return 400
169
170    @classmethod
171    @overrides
172    def name(cls) -> str:
173        return "QuotaError"
174
175
176error_types: Dict[str, Type[ChromaError]] = {
177    "InvalidDimension": InvalidDimensionException,
178    "InvalidArgumentError": InvalidArgumentError,
179    "IDAlreadyExists": IDAlreadyExistsError,
180    "DuplicateID": DuplicateIDError,
181    "InvalidUUID": InvalidUUIDError,
182    "InvalidHTTPVersion": InvalidHTTPVersion,
183    "AuthorizationError": AuthorizationError,
184    "NotFoundError": NotFoundError,
185    "BatchSizeExceededError": BatchSizeExceededError,
186    "VersionMismatchError": VersionMismatchError,
187    "RateLimitError": RateLimitError,
188    "AuthError": ChromaAuthError,
189    "UniqueConstraintError": UniqueConstraintError,
190    "QuotaError": QuotaError,
191    "InternalError": InternalError,
192    # Catch-all for any other errors
193    "ChromaError": ChromaError,
194}
195 
codekingpro/portable-devtools · Team Ai