Decorator error mapper
Project description
Error-mapper
Python error mapper based on decorators.
Installing
pip install error-mapper
Example
Error map
from error_mapper import ErrorMapType, error_map_decorator
class SuppressedError(Exception): ...
class RaiseError(Exception): ...
error_map: ErrorMapType = {
SuppressedError: RaiseError,
}
@error_map_decorator(error_map, RaiseError)
def fn() -> None:
raise SuppressedError
On error execute
from error_mapper import ErrorMapTypeExecute, on_error_execute
class SuppressedError(Exception): ...
class RaiseError(Exception): ...
def process_error(error: Exception) -> tp.NoReturn:
raise RaiseError from error
error_map: ErrorMapTypeExecute = {
SuppressedError: process_error,
}
@on_error_execute(error_map, RaiseError)
def fn() -> None:
raise SuppressedError
Suppress error to None
from error_mapper import suppress_to_none
class SuppressedError(Exception): ...
class RaiseError(Exception): ...
@suppress_to_none(SuppressedError)
def fn() -> None:
raise SuppressedError
assert fn() is None
Testing, linting, formatting
rye test
rye lint
rye fmt
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
error_mapper-1.0.4.tar.gz
(7.3 kB
view hashes)
Built Distribution
Close
Hashes for error_mapper-1.0.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ff5333ca0961c5fc69b4c210a2ff3f2a3b73890bb285a55888fc7902f1c090b4 |
|
MD5 | bc8bb458da1ed1e12177dcf297802ea5 |
|
BLAKE2b-256 | bc245577f58cb35b7204116e21ba74c2a8cb92231c19e221a5690d2fef85434b |