awesome-errors 0.3.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- awesome_errors/__init__.py +232 -0
- awesome_errors/analysis/__init__.py +8 -0
- awesome_errors/analysis/decorators.py +251 -0
- awesome_errors/analysis/error_analyzer.py +463 -0
- awesome_errors/client/__init__.py +7 -0
- awesome_errors/client/exceptions.py +97 -0
- awesome_errors/client/response_parser.py +175 -0
- awesome_errors/converters/__init__.py +31 -0
- awesome_errors/converters/generic.py +23 -0
- awesome_errors/converters/pydantic_converter.py +75 -0
- awesome_errors/converters/python_converter.py +80 -0
- awesome_errors/converters/sql_converter.py +258 -0
- awesome_errors/converters/universal_converter.py +123 -0
- awesome_errors/core/__init__.py +0 -0
- awesome_errors/core/error_codes.py +104 -0
- awesome_errors/core/error_response.py +61 -0
- awesome_errors/core/exceptions.py +613 -0
- awesome_errors/core/renderers.py +115 -0
- awesome_errors/i18n/__init__.py +0 -0
- awesome_errors/i18n/locales/en/errors.json +32 -0
- awesome_errors/i18n/locales/test/errors.json +4 -0
- awesome_errors/i18n/locales/uk/errors.json +26 -0
- awesome_errors/i18n/translator.py +150 -0
- awesome_errors/integrations/__init__.py +11 -0
- awesome_errors/integrations/fastapi_auto_docs.py +220 -0
- awesome_errors/litestar_utils.py +55 -0
- awesome_errors/middleware/__init__.py +0 -0
- awesome_errors/middleware/fastapi.py +247 -0
- awesome_errors/middleware/litestar.py +333 -0
- awesome_errors/py.typed +1 -0
- awesome_errors/websocket/__init__.py +35 -0
- awesome_errors/websocket/error_handler.py +231 -0
- awesome_errors/websocket/exceptions.py +286 -0
- awesome_errors-0.3.0.dist-info/METADATA +239 -0
- awesome_errors-0.3.0.dist-info/RECORD +37 -0
- awesome_errors-0.3.0.dist-info/WHEEL +4 -0
- awesome_errors-0.3.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: awesome-errors
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: A comprehensive error handling library for Python applications with i18n support
|
|
5
|
+
Project-URL: Homepage, https://github.com/THEROER/awesome-errors
|
|
6
|
+
Project-URL: Repository, https://github.com/THEROER/awesome-errors
|
|
7
|
+
Project-URL: Issues, https://github.com/THEROER/awesome-errors/issues
|
|
8
|
+
Author-email: THEROER <theroer09@gmail.com>
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: error-handling,exceptions,fastapi,i18n,litestar
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
16
|
+
Classifier: Typing :: Typed
|
|
17
|
+
Requires-Python: <4,>=3.10
|
|
18
|
+
Requires-Dist: msgspec<0.22,>=0.21.0
|
|
19
|
+
Provides-Extra: all
|
|
20
|
+
Requires-Dist: fastapi<0.116,>=0.115.14; extra == 'all'
|
|
21
|
+
Requires-Dist: litestar<3,>=2.21.1; extra == 'all'
|
|
22
|
+
Requires-Dist: pydantic[email]<3,>=2.0; extra == 'all'
|
|
23
|
+
Requires-Dist: sqlalchemy<3,>=2.0; extra == 'all'
|
|
24
|
+
Provides-Extra: fastapi
|
|
25
|
+
Requires-Dist: fastapi<0.116,>=0.115.14; extra == 'fastapi'
|
|
26
|
+
Requires-Dist: pydantic[email]<3,>=2.0; extra == 'fastapi'
|
|
27
|
+
Provides-Extra: litestar
|
|
28
|
+
Requires-Dist: litestar<3,>=2.21.1; extra == 'litestar'
|
|
29
|
+
Provides-Extra: pydantic
|
|
30
|
+
Requires-Dist: pydantic[email]<3,>=2.0; extra == 'pydantic'
|
|
31
|
+
Provides-Extra: sqlalchemy
|
|
32
|
+
Requires-Dist: sqlalchemy<3,>=2.0; extra == 'sqlalchemy'
|
|
33
|
+
Description-Content-Type: text/markdown
|
|
34
|
+
|
|
35
|
+
# Awesome Errors
|
|
36
|
+
|
|
37
|
+
A comprehensive Python library for standardized error handling, analysis, and documentation.
|
|
38
|
+
|
|
39
|
+
## Architecture Overview
|
|
40
|
+
|
|
41
|
+
### Core Components
|
|
42
|
+
|
|
43
|
+
#### 1. **Core Exceptions** (`src/awesome_errors/core/`)
|
|
44
|
+
|
|
45
|
+
- **AppError**: Base exception class for server-side error handling
|
|
46
|
+
- **ValidationError**: HTTP 400 errors for input validation failures
|
|
47
|
+
- **AuthError**: HTTP 401/403 errors for authentication/authorization
|
|
48
|
+
- **NotFoundError**: HTTP 404 errors for missing resources
|
|
49
|
+
- **DatabaseError**: HTTP 500/409/422 errors for database issues
|
|
50
|
+
- **BusinessLogicError**: HTTP 422 errors for business rule violations
|
|
51
|
+
|
|
52
|
+
#### 2. **Client Exceptions** (`src/awesome_errors/client/`)
|
|
53
|
+
|
|
54
|
+
- **BackendError**: Client-side exception for handling server responses
|
|
55
|
+
- **ErrorResponseParser**: Parser for backend error responses
|
|
56
|
+
|
|
57
|
+
**Key Difference**: Core exceptions are raised on the server, while client exceptions handle errors received from the server.
|
|
58
|
+
|
|
59
|
+
#### 3. **Error Converters** (`src/awesome_errors/converters/`)
|
|
60
|
+
|
|
61
|
+
- **UniversalErrorConverter**: Handles any type of exception
|
|
62
|
+
- **SQLErrorConverter**: Converts SQLAlchemy errors
|
|
63
|
+
- **PythonErrorConverter**: Converts standard Python exceptions
|
|
64
|
+
- **PydanticErrorConverter**: Converts Pydantic validation errors
|
|
65
|
+
- **generic_error_handler**: Shared logic for unknown errors
|
|
66
|
+
|
|
67
|
+
#### 4. **Analysis Tools** (`src/awesome_errors/analysis/`)
|
|
68
|
+
|
|
69
|
+
- **ErrorAnalyzer**: AST-based error analysis
|
|
70
|
+
- **analyze_errors**: Decorator for automatic error analysis
|
|
71
|
+
- **openapi_errors**: Decorator for OpenAPI documentation
|
|
72
|
+
|
|
73
|
+
#### 5. **HTTP Response Renderers** (`src/awesome_errors/core/renderers.py`)
|
|
74
|
+
|
|
75
|
+
- **ErrorResponseRenderer**: Produces either legacy envelopes or RFC 7807 documents
|
|
76
|
+
- **ErrorResponseFormat**: Toggle between response formats per application
|
|
77
|
+
|
|
78
|
+
#### 6. **Framework Integrations** (`src/awesome_errors/middleware/`)
|
|
79
|
+
|
|
80
|
+
- **FastAPI middleware**: `setup_error_handling`
|
|
81
|
+
- **Litestar handlers**: `create_litestar_exception_handlers`
|
|
82
|
+
|
|
83
|
+
#### 6. **Internationalization** (`src/awesome_errors/i18n/`)
|
|
84
|
+
|
|
85
|
+
- **ErrorTranslator**: Multi-language error message support
|
|
86
|
+
- Locale files in `src/awesome_errors/i18n/locales/`
|
|
87
|
+
|
|
88
|
+
#### 7. **Middleware** (`src/awesome_errors/middleware/`)
|
|
89
|
+
|
|
90
|
+
- **setup_error_handling**: FastAPI error handling middleware
|
|
91
|
+
|
|
92
|
+
## Usage Examples
|
|
93
|
+
|
|
94
|
+
### Server-Side Error Handling
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
from awesome_errors import ValidationError, NotFoundError, ErrorCode
|
|
98
|
+
|
|
99
|
+
# Validation error
|
|
100
|
+
raise ValidationError("Email is required", field="email")
|
|
101
|
+
|
|
102
|
+
# Not found error
|
|
103
|
+
raise NotFoundError("user", user_id=123)
|
|
104
|
+
|
|
105
|
+
# Custom error code
|
|
106
|
+
raise ValidationError("Invalid format", code=ErrorCode("CUSTOM_ERROR"))
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### Client-Side Error Handling
|
|
110
|
+
|
|
111
|
+
```python
|
|
112
|
+
from awesome_errors import BackendError
|
|
113
|
+
|
|
114
|
+
try:
|
|
115
|
+
response = api_client.get_user(123)
|
|
116
|
+
except BackendError as e:
|
|
117
|
+
if e.is_not_found_error():
|
|
118
|
+
print("User not found")
|
|
119
|
+
elif e.is_validation_error():
|
|
120
|
+
print("Invalid input")
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### FastAPI Integration
|
|
124
|
+
|
|
125
|
+
```python
|
|
126
|
+
from fastapi import FastAPI
|
|
127
|
+
from awesome_errors import setup_error_handling, auto_analyze_errors
|
|
128
|
+
|
|
129
|
+
app = FastAPI()
|
|
130
|
+
setup_error_handling(app)
|
|
131
|
+
|
|
132
|
+
@auto_analyze_errors
|
|
133
|
+
@app.get("/users/{user_id}")
|
|
134
|
+
def get_user(user_id: int):
|
|
135
|
+
if user_id == 404:
|
|
136
|
+
raise NotFoundError("user", user_id)
|
|
137
|
+
return {"id": user_id}
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### Litestar Integration
|
|
141
|
+
|
|
142
|
+
```python
|
|
143
|
+
from litestar import Litestar
|
|
144
|
+
from awesome_errors import (
|
|
145
|
+
ErrorResponseFormat,
|
|
146
|
+
ErrorTranslator,
|
|
147
|
+
create_litestar_exception_handlers,
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
translator = ErrorTranslator(default_locale="en")
|
|
151
|
+
translator.add_translations("en", {"CUSTOM": "Custom error"}, persist=False)
|
|
152
|
+
|
|
153
|
+
exception_handlers = create_litestar_exception_handlers(
|
|
154
|
+
translator=translator,
|
|
155
|
+
response_format=ErrorResponseFormat.RFC7807,
|
|
156
|
+
problem_type_resolver=lambda err: f"urn:demo:error:{err.code.value.lower()}",
|
|
157
|
+
)
|
|
158
|
+
|
|
159
|
+
app = Litestar(route_handlers=[...], exception_handlers=exception_handlers)
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### Error Analysis
|
|
163
|
+
|
|
164
|
+
```python
|
|
165
|
+
from awesome_errors import analyze_errors, openapi_errors
|
|
166
|
+
|
|
167
|
+
@analyze_errors()
|
|
168
|
+
def my_function():
|
|
169
|
+
raise ValidationError("Test error")
|
|
170
|
+
|
|
171
|
+
@openapi_errors(additional_errors=["CUSTOM_ERROR"])
|
|
172
|
+
def my_api_endpoint():
|
|
173
|
+
# Automatically documented in OpenAPI
|
|
174
|
+
pass
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
## Key Features
|
|
178
|
+
|
|
179
|
+
### ✅ **Unified Error Models**
|
|
180
|
+
|
|
181
|
+
- Lightweight msgspec structs used across server & client sides
|
|
182
|
+
- Single serialization layer for legacy and RFC 7807 formats
|
|
183
|
+
- Consistent error structure
|
|
184
|
+
|
|
185
|
+
### ✅ **Shared Generic Error Handling**
|
|
186
|
+
|
|
187
|
+
- Common `generic_error_handler` for unknown errors
|
|
188
|
+
- Used by all converters to avoid code duplication
|
|
189
|
+
- Debug mode support for detailed error information
|
|
190
|
+
|
|
191
|
+
### ✅ **Consolidated FastAPI Integration**
|
|
192
|
+
|
|
193
|
+
- Single entry point for all FastAPI integrations
|
|
194
|
+
- Automatic OpenAPI documentation generation
|
|
195
|
+
- Combined analysis and documentation decorators
|
|
196
|
+
|
|
197
|
+
### ✅ **Clean Architecture**
|
|
198
|
+
|
|
199
|
+
- Clear separation between server and client error handling
|
|
200
|
+
- Modular converter system
|
|
201
|
+
- Pluggable renderers for multiple frameworks
|
|
202
|
+
|
|
203
|
+
### ✅ **Internationalization Support**
|
|
204
|
+
|
|
205
|
+
- Multi-language error messages
|
|
206
|
+
- Locale-based translation
|
|
207
|
+
- Template parameter support
|
|
208
|
+
- Optional persistence when extending translations at runtime
|
|
209
|
+
|
|
210
|
+
## Installation
|
|
211
|
+
|
|
212
|
+
```bash
|
|
213
|
+
pip install awesome-errors
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
## Development
|
|
217
|
+
|
|
218
|
+
```bash
|
|
219
|
+
# Install dependencies
|
|
220
|
+
uv sync --dev
|
|
221
|
+
|
|
222
|
+
# Run tests
|
|
223
|
+
uv run pytest
|
|
224
|
+
|
|
225
|
+
# Run linting
|
|
226
|
+
uv run ruff check src/
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
## Contributing
|
|
230
|
+
|
|
231
|
+
1. Fork the repository
|
|
232
|
+
2. Create a feature branch
|
|
233
|
+
3. Make your changes
|
|
234
|
+
4. Add tests
|
|
235
|
+
5. Submit a pull request
|
|
236
|
+
|
|
237
|
+
## License
|
|
238
|
+
|
|
239
|
+
MIT License - see LICENSE file for details.
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
awesome_errors/__init__.py,sha256=JseznpKN9GGclhG1u1NDbot_vkQiit9nzHJzb_BUGZk,7795
|
|
2
|
+
awesome_errors/litestar_utils.py,sha256=FOEmwQNAwFvRAIIQJ4tSHOfifmWSjFh2SEEd53xlWz0,1765
|
|
3
|
+
awesome_errors/py.typed,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
|
4
|
+
awesome_errors/analysis/__init__.py,sha256=Yk2xHQKZfi6n9qOVkx59paVLKUvgdNOSvU1StAacw5s,177
|
|
5
|
+
awesome_errors/analysis/decorators.py,sha256=qtBisesbukim5KmGQjdDmwCKo0z32fpFeT9vHj3SM_s,8607
|
|
6
|
+
awesome_errors/analysis/error_analyzer.py,sha256=aIIMTubtb9PoQJxcaZaNvrEUw-9IjHIb8GlHaavKn7U,17122
|
|
7
|
+
awesome_errors/client/__init__.py,sha256=5prGsahGFMH_Ld-EPhdR2c_QvSB8sZ4U6-H5NKtL55k,148
|
|
8
|
+
awesome_errors/client/exceptions.py,sha256=ZEspKS7tHWxfVlFPzDffPQS7RS-gr0PiLfVuJrmfo6k,2999
|
|
9
|
+
awesome_errors/client/response_parser.py,sha256=Xd1ZvdFN4o2xbG6Yy99aUIFH1p-oamI6WrAUIlt4yeI,5829
|
|
10
|
+
awesome_errors/converters/__init__.py,sha256=Dm52R-BJRQTtnHmah4ToO6uPqPOsB97zUGKRhbY4CoQ,944
|
|
11
|
+
awesome_errors/converters/generic.py,sha256=oiCLd25YRQTIaW7V4yEMSj0cmzUJ4JkfFoUnjRPR2TY,773
|
|
12
|
+
awesome_errors/converters/pydantic_converter.py,sha256=i-QH2ZOOAZg8wT3SfVY5yZ1jy2iqHA1jg_jFoY0zcL0,2558
|
|
13
|
+
awesome_errors/converters/python_converter.py,sha256=eGRbMR2D27rz-0I6R1nZhBVdOtUN9X5-NmM96K3rf54,3264
|
|
14
|
+
awesome_errors/converters/sql_converter.py,sha256=zYaRBmewb-22Kg3_U3m3kiiMY6tVM5jy6TI109517RA,9210
|
|
15
|
+
awesome_errors/converters/universal_converter.py,sha256=Kgv5RTDZenxptLUM4lNYn6GYeFIR65b7LeaR_3gf1b4,4186
|
|
16
|
+
awesome_errors/core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
17
|
+
awesome_errors/core/error_codes.py,sha256=nSigfn8jv7SKdcIsziyPkXUFMD4TLOpARvxtzRZzlmo,3629
|
|
18
|
+
awesome_errors/core/error_response.py,sha256=uIkkdNlGgNM3lh_sdoSzeAtC7QC04lgBEL0rYR407kM,1997
|
|
19
|
+
awesome_errors/core/exceptions.py,sha256=YWOIlg3BAKobAXAXwuw5jlDkUMzxbSFIoOwYDD507TA,20017
|
|
20
|
+
awesome_errors/core/renderers.py,sha256=8pGVvTwZ4f0lLF2jqWKKJlCPY78QmdUg6Nzsnci9pNE,3372
|
|
21
|
+
awesome_errors/i18n/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
22
|
+
awesome_errors/i18n/translator.py,sha256=3BmQUA-zihcbNC4GfSvi8tg2qPIFbsbgRo0MPdLkBO8,5728
|
|
23
|
+
awesome_errors/i18n/locales/en/errors.json,sha256=srm5S_30DUrPa-cAYdeEHleSCtL-EUnJ4yW_xCkliSU,1484
|
|
24
|
+
awesome_errors/i18n/locales/test/errors.json,sha256=UJ6fNqEhQNZ5CR47LeA8oUJN5pB9BG1pdiSLt_U76Zg,143
|
|
25
|
+
awesome_errors/i18n/locales/uk/errors.json,sha256=8JutDgqx9QDv-QF5Y5WDfgmeN6ocKZrzarVG1bMcNEo,1727
|
|
26
|
+
awesome_errors/integrations/__init__.py,sha256=FoloNy-8vdJg3OWqsoGrMLiAtJDhre7RVX1hCu5YKKM,244
|
|
27
|
+
awesome_errors/integrations/fastapi_auto_docs.py,sha256=ph7Q7-zgkhWTcoNabHdTTOaVBIe-_0qZXZ9WoI3Qr80,8183
|
|
28
|
+
awesome_errors/middleware/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
29
|
+
awesome_errors/middleware/fastapi.py,sha256=6PS5WGIXTFkht2vruVi9g_ByM1ZEOW1Jw56G1H4NlLM,8728
|
|
30
|
+
awesome_errors/middleware/litestar.py,sha256=9w7hW_SNr3bUKwij9uiyg8qDmk6TyF6MDsQttRmQiuU,12252
|
|
31
|
+
awesome_errors/websocket/__init__.py,sha256=4JcGSF3o8rLLdINWPl6_QQ_BxAAk1Gm0eXOIasq51Eg,806
|
|
32
|
+
awesome_errors/websocket/error_handler.py,sha256=FWHi_ROBTGcp5h2m-U8wxxX5r9lPHV4DQOpBHlzxsSY,8413
|
|
33
|
+
awesome_errors/websocket/exceptions.py,sha256=pg95MZEbyN_TMgl6Rm7TFL6iLAOpl4mM0gJ95iOslHI,9853
|
|
34
|
+
awesome_errors-0.3.0.dist-info/METADATA,sha256=BgJFOvcw5WUa3_5CpVKTJAEmHZJN-9PWc3kfmn1pG84,6967
|
|
35
|
+
awesome_errors-0.3.0.dist-info/WHEEL,sha256=lCkmxWfQsSc9CfIClYeavTdQeEX2toPqufh9gI35EQA,87
|
|
36
|
+
awesome_errors-0.3.0.dist-info/licenses/LICENSE,sha256=x32be04GnNO7nJ-rLN10jombmqZkbnJFrBjgzQI6fhk,1064
|
|
37
|
+
awesome_errors-0.3.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 THEROER
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|