errorhelpers
Helpers for handling Python errors.
Usage:
# As a decorator
@errorhelpers.expect_error(*errors, on_unexpected_error=handler)
def some_error_prone_funcion():
...
# Using with statement
with errorhelpers.expect_error(*errors, on_unexpected_error=handler):
# Some error prone operation
...
Example 1: Basic usage
import pytest
import errorhelpers
with errorhelpers.expect_errors(ZeroDivisionError):
assert 4 / 2 == 2
# `ZeroDivisionError` will be re-raised.
with pytest.raises(ZeroDivisionError):
with errorhelpers.expect_errors(ZeroDivisionError):
4 / 0
# In case of other exceptions, `errorhelpers.UnexpectedError("Unexpected error")`
# will be raised instead.
with pytest.raises(errorhelpers.UnexpectedError, match="Unexpected error"):
with errorhelpers.expect_errors(ZeroDivisionError):
"a" / "b"
Example 2: Custom error
import pytest
import errorhelpers
class CustomError(Exception):
@classmethod
def raise_(cls, msg):
def raiser(error):
print("Hiding error:", error)
raise cls(msg)
return raiser
@errorhelpers.expect_errors(
ZeroDivisionError, on_unexpected_error=CustomError.raise_("Custom error")
)
def sensitive_transaction(x, y):
return int(x) / int(y)
assert sensitive_transaction(4, "2") == 2
# `ZeroDivisionError` will be re-raised.
with pytest.raises(ZeroDivisionError):
sensitive_transaction(4, 0)
# In case of other exceptions, `CustomError` will be raised instead.
with pytest.raises(CustomError, match="Custom error"):
sensitive_transaction("a", "b")
# Hiding error: invalid literal for int() with base 10: 'a'
Metadata
Release files for errorhelpers 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| errorhelpers-0.2.0.tar.gz | 3.5 kB | Without provenance | Details for errorhelpers-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| errorhelpers-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for errorhelpers-0.2.0-py3-none-any.whl |
Total release size: 7.2 kB
Release files / errorhelpers-0.2.0.tar.gz
| Download URL | errorhelpers-0.2.0.tar.gz |
|---|---|
| Size | 3.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
109e0f5b9fa3b144a31870c10957a77777570f158151285ddf53860343d60cf3
|
|
BLAKE2b-256 checksum How to use checksums |
71888db9c4c044cdb37bc88567e768048c9bf80a1a2efdf1e7cbb2328d104094
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.4 CPython/3.8.8 Linux/5.9.16-1-MANJARO
|
Release files / errorhelpers-0.2.0-py3-none-any.whl
| Download URL | errorhelpers-0.2.0-py3-none-any.whl |
|---|---|
| Size | 3.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3d3a660eb88c4f5ed4a65570685828735e22a55cc1f94870f9039cdb097228d1
|
|
BLAKE2b-256 checksum How to use checksums |
7d45f526ba5717082cfe86e3c1e0f9258a18e9438cf0e45eb3455345a2da3417
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.4 CPython/3.8.8 Linux/5.9.16-1-MANJARO
|
Security for errorhelpers 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.