Skip to main content

Type-safe error handling for Python.

Project description

errs

https://img.shields.io/pypi/v/errs.svg https://img.shields.io/travis/nicksettje/errs.svg https://codecov.io/gh/nicksettje/errs/branch/master/graph/badge.svg Documentation Status Updates

Type-safe error handling for Python.

Installation

pip install errs

Usage

The @errs decorator marks any function or method that raises an Exception. Rather than handling the Exception explicitly, we collect the result of the function and then check whether an error occurred.

This leads to code that is more explicit about error handling as well as resilient to the raising of unforeseen exceptions. This style is similar to error handling in Go.

Additionally, all exceptions wrapped by @errs will be logged to the default Python logger on the error level. This provides a powerful abstraction where runtime behaviors are logged and separated from current application state.

from errs import errs

@errs
def raises(): #type: () -> int
    raise Exception('this will get logged')
    return 0

def check_error(): #type: () -> None
    out, err = raises()
    print('Error: {err}'.format(err.check()))

if __name__ == '__main__':
    check_error() #prints Error: True

Credits

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.

History

0.1.0 (2018-12-30)

  • First release on PyPI.

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

errs-0.1.1.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

errs-0.1.1-py2.py3-none-any.whl (4.5 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file errs-0.1.1.tar.gz.

File metadata

  • Download URL: errs-0.1.1.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.3

File hashes

Hashes for errs-0.1.1.tar.gz
Algorithm Hash digest
SHA256 e88f2bf2baf54fed3226a50b8df04ca51c759ae45d9659ccc2ed4a193bc62954
MD5 2b36dfa58108c5b870dd10f3e69f86c6
BLAKE2b-256 eb623090db52875d33c816939151d25c6209c9dac8bfced8be1725dc2d1ff380

See more details on using hashes here.

File details

Details for the file errs-0.1.1-py2.py3-none-any.whl.

File metadata

  • Download URL: errs-0.1.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 4.5 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.3

File hashes

Hashes for errs-0.1.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 7aae2b0ac5233961a5aff64ae69c527d7d64159a075170a7750f004299bbb9d6
MD5 69dffc33f2dae925a0c89fd80b37969f
BLAKE2b-256 c623ecb1c6bf065ce316b122bc152e0f1998516d98e729370388d5788e3fac25

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