Go like errors for Python
Project description
pygoerrors
A Python library that brings Go-style error handling to Python, enabling error values, wrapping, and inspection without relying on exceptions.
🚀 Features
- Error Values: Return errors as values instead of raising exceptions.
- Error Wrapping: Wrap errors with contextual messages, similar to Go's fmt.Errorf("...: %w", err).
- Error Inspection: Traverse error chains using unwrap(), is_(), and as_().
- Protocol-Based Design: Utilize Python's Protocol to define error interfaces.
- No Exceptions: Emphasize functional programming by avoiding exceptions entirely.
📦 Installation
Install the package using pip:
pip install pygoerrors
🧑💻 Usage
Defining Custom Errors
import pygoerrors
MyOtherError = pygoerrors.new("some error")
class MyErrorClass(pygoerrors.Error):
def error(self) -> str:
return "some error"
Wrapping Errors
import pygoerrors
class MyErrorClass(pygoerrors.Error):
def error(self) -> str:
return "base error"
base_err = MyErrorClass()
assert base_err.error() == "base error"
wrapped_err = pygoerrors.errorf("wrapped: %w", base_err)
assert wrapped_err.error() == "wrapped: base error"
Inspecting Errors
import pygoerrors
class MyErrorClass(pygoerrors.Error):
def error(self) -> str:
return "base error"
base_err = MyErrorClass()
assert base_err.error() == "base error"
wrapped_err = pygoerrors.errorf("wrapped: %w", base_err)
assert wrapped_err.error() == "wrapped: base error"
assert pygoerrors.is_(wrapped_err, MyErrorClass())
instance = pygoerrors.as_(err, MyErrorClass)
assert instance.error() == "base error"
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pygoerrors-0.2.0.tar.gz.
File metadata
- Download URL: pygoerrors-0.2.0.tar.gz
- Upload date:
- Size: 29.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
96240980a00a0fe23af65c0b3eeb716c7f290d5a7ae156bf12ddfb7a08b2add7
|
|
| MD5 |
532696f042489b5cb69780bc4d28f077
|
|
| BLAKE2b-256 |
9f0df7ece90a9355044a5c0110fbf473bb74e226dd068b7710a937d9fbe49768
|
Provenance
The following attestation bundles were made for pygoerrors-0.2.0.tar.gz:
Publisher:
release.yaml on dreadster3/pygoerrors
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pygoerrors-0.2.0.tar.gz -
Subject digest:
96240980a00a0fe23af65c0b3eeb716c7f290d5a7ae156bf12ddfb7a08b2add7 - Sigstore transparency entry: 236633912
- Sigstore integration time:
-
Permalink:
dreadster3/pygoerrors@20970bb9c38a5ce98f343bc9ae105bdf2531b812 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/dreadster3
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@20970bb9c38a5ce98f343bc9ae105bdf2531b812 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pygoerrors-0.2.0-py3-none-any.whl.
File metadata
- Download URL: pygoerrors-0.2.0-py3-none-any.whl
- Upload date:
- Size: 30.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fe778fdbbde2140f666e7c2ed94da39a3c55b18f9f65aa732cf872b3e83689bd
|
|
| MD5 |
ce2fee43e618cc68fdc8791f87d8d6e2
|
|
| BLAKE2b-256 |
88360510a69240ea3409a7e26364ce3cea377e26312b0ad5c664f9fb6c3c198d
|
Provenance
The following attestation bundles were made for pygoerrors-0.2.0-py3-none-any.whl:
Publisher:
release.yaml on dreadster3/pygoerrors
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pygoerrors-0.2.0-py3-none-any.whl -
Subject digest:
fe778fdbbde2140f666e7c2ed94da39a3c55b18f9f65aa732cf872b3e83689bd - Sigstore transparency entry: 236633918
- Sigstore integration time:
-
Permalink:
dreadster3/pygoerrors@20970bb9c38a5ce98f343bc9ae105bdf2531b812 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/dreadster3
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@20970bb9c38a5ce98f343bc9ae105bdf2531b812 -
Trigger Event:
push
-
Statement type: