Metadata-Version: 2.3
Name: error-mapper
Version: 1.0.1
Summary: Decorator error mapper
Project-URL: Homepage, https://pypi.org/project/error-mapper/
Project-URL: Repository, https://github.com/likeinlife/error_mapper
Author-email: likeinlife <likeinlife@outlook.com>
License: MIT License
        
        Copyright (c) 2024 likeinlife
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: decorator,error mapping
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.11
Description-Content-Type: text/markdown

# Error-mapper

[![image](https://img.shields.io/pypi/v/error-mapper.svg)](https://pypi.python.org/pypi/error-mapper)
[![image](https://img.shields.io/pypi/l/error-mapper.svg)](https://github.com/likeinlife/error-mapper/blob/main/LICENSE)
<a href="http://mypy-lang.org/" target="_blank"><img src="https://img.shields.io/badge/mypy-checked-1F5082.svg" alt="Mypy checked"></a>
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
[![image](https://img.shields.io/pypi/pyversions/error-mapper.svg)](https://pypi.python.org/pypi/error-mapper)

Python error mapper based on decorators.

# Installing

`pip install error-mapper`

# Example

## Error map

```python
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

```python
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
```

# Testing, linting, formatting

- `rye test`
- `rye lint`
- `rye fmt`