Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kkristof200/py_noraise
https://github.com/kkristof200/py_noraise
Last synced: 10 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/kkristof200/py_noraise
- Owner: kkristof200
- License: mit
- Created: 2021-01-10T20:52:33.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2021-04-17T22:34:55.000Z (over 3 years ago)
- Last Synced: 2024-10-12T21:06:26.943Z (about 1 month ago)
- Language: Python
- Size: 13.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# noraise
![PyPI - package version](https://img.shields.io/pypi/v/noraise?logo=pypi&style=flat-square)
![PyPI - license](https://img.shields.io/pypi/l/noraise?label=package%20license&style=flat-square)
![PyPI - python version](https://img.shields.io/pypi/pyversions/noraise?logo=pypi&style=flat-square)
![PyPI - downloads](https://img.shields.io/pypi/dm/noraise?logo=pypi&style=flat-square)![GitHub - last commit](https://img.shields.io/github/last-commit/kkristof200/py_noraise?style=flat-square)
![GitHub - commit activity](https://img.shields.io/github/commit-activity/m/kkristof200/py_noraise?style=flat-square)![GitHub - code size in bytes](https://img.shields.io/github/languages/code-size/kkristof200/py_noraise?style=flat-square)
![GitHub - repo size](https://img.shields.io/github/repo-size/kkristof200/py_noraise?style=flat-square)
![GitHub - lines of code](https://img.shields.io/tokei/lines/github/kkristof200/py_noraise?style=flat-square)![GitHub - license](https://img.shields.io/github/license/kkristof200/py_noraise?label=repo%20license&style=flat-square)
## Description
Lightweight utility package, that provides a function decorator to easily catch and print exceptions
## Supported Args
| name | type | default value | description |
|----------------------|---------------------------|---------------|---------------------------------------------------------------------------------|
| print_exc | bool | True | If True, prints stacktrace |
| return_exception | bool | False | If True, returns caught exception |
| default_return_value | Optional[any] | None | What to return upon caught exception if
'return_exception' is False |
| ignored_error_types | Optional[List[Exception]] | None | In which cases should the stacktrace print
be skipped if 'print_exc' is True |## Install
~~~~bash
pip install noraise
# or
pip3 install noraise
~~~~## Usage
~~~~python
from noraise import noraise@noraise(print_exc=True, return_exception=True, ignored_error_types=[ZeroDivisionError])
def f2():
return 1/0res = f2()
print(type(res), res)# This will not catch the crash, and print
#
#
# < ------------------------------------- Caught with @noraise ------------------------------------ >
#
# Traceback (most recent call last):
# File "/Users/kristofk/github/py_noraise/noraise/noraise.py", line 32, in wrapper
# return function(*args, **kwargs)
# File "demo.py", line 5, in f2
# return 1/0
# ZeroDivisionError: division by zero
#
# < ----------------------------------------------------------------------------------------------- >
#
#
# division by zero
~~~~## Dependencies