Skip to main content

Decorator error mapper

Project description

Error-mapper

image image codecov Mypy checked Ruff image

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


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.6.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

error_mapper-1.0.6-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file error_mapper-1.0.6.tar.gz.

File metadata

  • Download URL: error_mapper-1.0.6.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.3

File hashes

Hashes for error_mapper-1.0.6.tar.gz
Algorithm Hash digest
SHA256 5fb9c1128c54d73a6cf7586271f76bb4d1d7c10314ea4c7d7b2cc6ef793b9288
MD5 f2d82b18f4a5e8d73dca9bbbb237efb0
BLAKE2b-256 c45d8f630dda4644a8bdb973375076007cec44a9be2eefcb042ad2deb280815c

See more details on using hashes here.

File details

Details for the file error_mapper-1.0.6-py3-none-any.whl.

File metadata

File hashes

Hashes for error_mapper-1.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 65d764ecdedc3adcbaa8ab718cf148fdcf23b151e2345530f5c8dbf4b477c384
MD5 7fc89bedd75c995a2530240e79ddc237
BLAKE2b-256 fe8b456c490dab9578b596cd75a6b39d53b0306da6bf7f5653b8c840572a0aba

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page