errr
Elegantly create detailed exceptions in Python.
Detailed exceptions
>>> import errr
>>> class MyException(errr.DetailedException, list_detailts=True, details=["cause", "type"]):
... pass
...
>>> example = MyException("The backend server crashed", "backend", "crash")
>>> raise example
__main__.MyException: The backend server crashed
Details:
˪cause: backend
˪type: crash
>>> example.details
{'cause': 'backend', 'type': 'crash'}
>>> example.cause
'backend'
Semantic exceptions
You can also rapidly create large semantic trees of exceptions using the make_tree
function, listing exceptions as keyword arguments using the errr.exception factory
method. The make_tree method executes these recursive factories to produce your
exceptions. Nesting these factory methods will make the resultant exceptions inherit from
eachother. All of the produced exceptions are then flat injected into the given module
dictionary (typically) this should be globals() but you can inject into other modules
using sys.modules["name"].__dict__.
from errr import make_tree, exception as _e
make_tree(
# Pass the module dictionary as first argument
globals(),
# List your nested exceptions
RootException=_e(
ChildException=_e(),
Child2Exception=_e()
),
SecondRootException=_e(
# List details as positional arguments
"detail1", "detail2",
# And continue with child exceptions as keyword arguments
AnotherChildException=_e()
)
)
print(RootException)
# <class '__main__.RootException'>
print(ChildException)
# <class '__main__.ChildException'>
print(ChildException.__bases__)
# (<class '__main__.RootException'>,)
Exception wrapping
You can catch and reraise exceptions as a new type of exception with the wrap function:
import errr
class LibraryError(errr.DetailedException, details=["library"]):
pass
for name, library in libraries.items():
try:
library.load()
except Exception as e:
errr.wrap(LibraryError, e, name, prepend="When trying to load %library% it reported:\n")
# Traceback
# ...
# __main__.LibraryError: When trying to load myLibrary it reported:
# Module 'missing' not found.
Metadata
Release files for errr 1.2.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| errr-1.2.2.tar.gz | 8.6 kB | Without provenance | Details for errr-1.2.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| errr-1.2.2-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details for errr-1.2.2-py2.py3-none-any.whl |
Total release size: 14.2 kB
Release files / errr-1.2.2.tar.gz
| Download URL | errr-1.2.2.tar.gz |
|---|---|
| Size | 8.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
40561a8b4e496f3458eb9174229b3752701396ece69c2cf3d382f4ebb6344bd1
|
|
BLAKE2b-256 checksum How to use checksums |
58fee6fe4ee3d283354e6a4ce1e8296dee78bf40e0f580002349bc90cbbf8e01
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.32.3
|
Release files / errr-1.2.2-py2.py3-none-any.whl
| Download URL | errr-1.2.2-py2.py3-none-any.whl |
|---|---|
| Size | 5.6 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
e4baa9ab30a1848ddd1d3571207bfcc2e4127230e92caa36a5fd0f463362431b
|
|
BLAKE2b-256 checksum How to use checksums |
eab32db1656dc3bb0c50485e7f20ab81cc92b0a9c6269906838f54b0fe76c591
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.32.3
|
Security for errr 1.2.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.