exceptions_with_structure 1.1.0.post1__tar.gz → 1.2.0__tar.gz
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.
- {exceptions_with_structure-1.1.0.post1 → exceptions_with_structure-1.2.0}/.gitignore +4 -4
- {exceptions_with_structure-1.1.0.post1 → exceptions_with_structure-1.2.0}/PKG-INFO +1 -1
- {exceptions_with_structure-1.1.0.post1 → exceptions_with_structure-1.2.0}/README.md +42 -42
- {exceptions_with_structure-1.1.0.post1 → exceptions_with_structure-1.2.0}/pyproject.toml +1 -1
- {exceptions_with_structure-1.1.0.post1 → exceptions_with_structure-1.2.0}/src/py/Exceptions.py +44 -42
- {exceptions_with_structure-1.1.0.post1 → exceptions_with_structure-1.2.0}/src/py/__init__.py +0 -0
- {exceptions_with_structure-1.1.0.post1 → exceptions_with_structure-1.2.0}/src/py/utils.py +4 -4
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
.venv
|
|
2
|
-
dist
|
|
3
|
-
cache
|
|
4
|
-
out
|
|
1
|
+
.venv
|
|
2
|
+
dist
|
|
3
|
+
cache
|
|
4
|
+
out
|
|
5
5
|
__pycache__
|
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
# exceptions_with_structure
|
|
2
|
-
|
|
3
|
-
A small Python package providing `StructuredException`, an exception with a
|
|
4
|
-
machine-readable error code and an ISO-8601 creation timestamp.
|
|
5
|
-
|
|
6
|
-
## Installation
|
|
7
|
-
|
|
8
|
-
```bash
|
|
9
|
-
pip install exceptions_with_structure
|
|
10
|
-
```
|
|
11
|
-
|
|
12
|
-
## Usage
|
|
13
|
-
|
|
14
|
-
```python
|
|
15
|
-
from py import StructuredException
|
|
16
|
-
|
|
17
|
-
try:
|
|
18
|
-
raise StructuredException("File not found", "IO_ERR_404")
|
|
19
|
-
except StructuredException as error:
|
|
20
|
-
print(error)
|
|
21
|
-
print(error.error_code)
|
|
22
|
-
print(error.timestamp)
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
`StructuredException` accepts a human-readable `message` and an `error_code`.
|
|
26
|
-
The `timestamp` field is generated when the exception is created.
|
|
27
|
-
|
|
28
|
-
## Development
|
|
29
|
-
|
|
30
|
-
From this directory, install the package in editable mode:
|
|
31
|
-
|
|
32
|
-
```bash
|
|
33
|
-
pip install -e .
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
Build distributable archives with:
|
|
37
|
-
|
|
38
|
-
```bash
|
|
39
|
-
python -m build
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
The package requires Python 3.8 or newer and is licensed under EUPL-1.2.
|
|
1
|
+
# exceptions_with_structure
|
|
2
|
+
|
|
3
|
+
A small Python package providing `StructuredException`, an exception with a
|
|
4
|
+
machine-readable error code and an ISO-8601 creation timestamp.
|
|
5
|
+
|
|
6
|
+
## Installation
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
pip install exceptions_with_structure
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Usage
|
|
13
|
+
|
|
14
|
+
```python
|
|
15
|
+
from py import StructuredException
|
|
16
|
+
|
|
17
|
+
try:
|
|
18
|
+
raise StructuredException("File not found", "IO_ERR_404")
|
|
19
|
+
except StructuredException as error:
|
|
20
|
+
print(error)
|
|
21
|
+
print(error.error_code)
|
|
22
|
+
print(error.timestamp)
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
`StructuredException` accepts a human-readable `message` and an `error_code`.
|
|
26
|
+
The `timestamp` field is generated when the exception is created.
|
|
27
|
+
|
|
28
|
+
## Development
|
|
29
|
+
|
|
30
|
+
From this directory, install the package in editable mode:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
pip install -e .
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Build distributable archives with:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
python -m build
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
The package requires Python 3.8 or newer and is licensed under EUPL-1.2.
|
{exceptions_with_structure-1.1.0.post1 → exceptions_with_structure-1.2.0}/src/py/Exceptions.py
RENAMED
|
@@ -1,43 +1,45 @@
|
|
|
1
|
-
from .utils import iso8601
|
|
2
|
-
|
|
3
|
-
class StructuredException(Exception):
|
|
4
|
-
"""Base class for all structured errors."""
|
|
5
|
-
def __init__(self, message: str, error_code: str):
|
|
6
|
-
super().__init__(message)
|
|
7
|
-
self.timestamp = iso8601()
|
|
8
|
-
self.error_code = error_code
|
|
9
|
-
|
|
10
|
-
# Dynamically create specific error types to avoid code duplication
|
|
11
|
-
def _create_structured_error(base_class: type[Exception], name: str) -> type[StructuredException]:
|
|
12
|
-
class NewStructuredError(StructuredException, base_class):
|
|
13
|
-
pass
|
|
14
|
-
NewStructuredError.__name__ = name
|
|
15
|
-
NewStructuredError.__qualname__ = name
|
|
16
|
-
return NewStructuredError
|
|
17
|
-
|
|
18
|
-
StructuredKeyError = _create_structured_error(KeyError, "StructuredKeyError")
|
|
19
|
-
StructuredTabError = _create_structured_error(TabError, "StructuredTabError")
|
|
20
|
-
StructuredNameError = _create_structured_error(NameError, "StructuredNameError")
|
|
21
|
-
StructuredTypeError = _create_structured_error(TypeError, "StructuredTypeError")
|
|
22
|
-
StructuredValueError = _create_structured_error(ValueError, "StructuredValueError")
|
|
23
|
-
StructuredIndexError = _create_structured_error(IndexError, "StructuredIndexError")
|
|
24
|
-
StructuredBufferError = _create_structured_error(BufferError, "StructuredBufferError")
|
|
25
|
-
StructuredEOFError = _create_structured_error(EOFError, "StructuredEOFError")
|
|
26
|
-
StructuredImportError = _create_structured_error(ImportError, "StructuredImportError")
|
|
27
|
-
StructuredLookupError = _create_structured_error(LookupError, "StructuredLookupError")
|
|
28
|
-
StructuredMemoryError = _create_structured_error(MemoryError, "StructuredMemoryError")
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
1
|
+
from .utils import iso8601
|
|
2
|
+
|
|
3
|
+
class StructuredException(Exception):
|
|
4
|
+
"""Base class for all structured errors."""
|
|
5
|
+
def __init__(self, message: str, error_code: str):
|
|
6
|
+
super().__init__(message)
|
|
7
|
+
self.timestamp = iso8601()
|
|
8
|
+
self.error_code = error_code
|
|
9
|
+
|
|
10
|
+
# Dynamically create specific error types to avoid code duplication
|
|
11
|
+
def _create_structured_error(base_class: type[Exception], name: str) -> type[StructuredException]:
|
|
12
|
+
class NewStructuredError(StructuredException, base_class):
|
|
13
|
+
pass
|
|
14
|
+
NewStructuredError.__name__ = name
|
|
15
|
+
NewStructuredError.__qualname__ = name
|
|
16
|
+
return NewStructuredError
|
|
17
|
+
|
|
18
|
+
StructuredKeyError = _create_structured_error(KeyError, "StructuredKeyError")
|
|
19
|
+
StructuredTabError = _create_structured_error(TabError, "StructuredTabError")
|
|
20
|
+
StructuredNameError = _create_structured_error(NameError, "StructuredNameError")
|
|
21
|
+
StructuredTypeError = _create_structured_error(TypeError, "StructuredTypeError")
|
|
22
|
+
StructuredValueError = _create_structured_error(ValueError, "StructuredValueError")
|
|
23
|
+
StructuredIndexError = _create_structured_error(IndexError, "StructuredIndexError")
|
|
24
|
+
StructuredBufferError = _create_structured_error(BufferError, "StructuredBufferError")
|
|
25
|
+
StructuredEOFError = _create_structured_error(EOFError, "StructuredEOFError")
|
|
26
|
+
StructuredImportError = _create_structured_error(ImportError, "StructuredImportError")
|
|
27
|
+
StructuredLookupError = _create_structured_error(LookupError, "StructuredLookupError")
|
|
28
|
+
StructuredMemoryError = _create_structured_error(MemoryError, "StructuredMemoryError")
|
|
29
|
+
StructuredSyntaxError = _create_structured_error(SyntaxError, "StructuredSyntaxError")
|
|
30
|
+
StructuredRuntimeError = _create_structured_error(RuntimeError, "StructuredRuntimeError")
|
|
31
|
+
|
|
32
|
+
__all__ = [
|
|
33
|
+
"StructuredException",
|
|
34
|
+
"StructuredKeyError",
|
|
35
|
+
"StructuredTabError",
|
|
36
|
+
"StructuredNameError",
|
|
37
|
+
"StructuredTypeError",
|
|
38
|
+
"StructuredValueError",
|
|
39
|
+
"StructuredIndexError",
|
|
40
|
+
"StructuredBufferError",
|
|
41
|
+
"StructuredEOFError",
|
|
42
|
+
"StructuredImportError",
|
|
43
|
+
"StructuredLookupError",
|
|
44
|
+
"StructuredMemoryError",
|
|
43
45
|
]
|
{exceptions_with_structure-1.1.0.post1 → exceptions_with_structure-1.2.0}/src/py/__init__.py
RENAMED
|
File without changes
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
from datetime import datetime
|
|
2
|
-
|
|
3
|
-
def iso8601() -> str: return datetime.now().isoformat()
|
|
4
|
-
|
|
1
|
+
from datetime import datetime
|
|
2
|
+
|
|
3
|
+
def iso8601() -> str: return datetime.now().isoformat()
|
|
4
|
+
|
|
5
5
|
__all__ = ["iso8601"]
|