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.

Files for errs, version 0.1.1
Filename, size File type Python version Upload date Hashes
Filename, size errs-0.1.1-py2.py3-none-any.whl (4.5 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size errs-0.1.1.tar.gz (9.3 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page