A callable interface for structured exceptions
This project has been archived.
The maintainers of this project have marked this project as archived. No new releases are expected.
Project description
No Exceptions
A callable interface for structured exceptions in Python, allowing dynamic registration of error codes, soft (non-raising) codes, exception propagation with context, and grouping multiple errors.
Features
Dynamic Error Codes: Register custom error codes with default messages at runtime.
Soft Errors: Define codes that don’t immediately raise exceptions, useful for warning accumulation.
Error Propagation: Wrap existing exceptions under new error codes while preserving context.
Exception Linking: Attach underlying exceptions to your custom errors for full traceability.
ExceptionGroup Support: Bundle multiple error codes into a single ExceptionGroup.
Rich String Output: Automatically include codes, messages, linked exceptions, and stack traces when converting to string.
Installation
Requires Python 3.11 or newer.
From PyPI
pip install noexcept
From source
git clone <repo-url>
cd noexcept
pip install .
Quick Start
Import the callable exception handler and register your error codes:
import no
Register codes at startup
no.register(404, "Not Found") # Standard error
no.register(500, "Server Error") # Standard error
no.register(123, "Soft Error", soft=True) # Soft (non-raising)
Raising an Exception
from no.module import no
try:
no(404)
except no.xcpt as e:
print(str(e))
# Output:
# [404]
# Not Found
Soft Errors
Soft codes don’t immediately raise:
no(123) # No exception is thrown because code 123 is registered as soft
Propagating Errors
Wrap an existing exception under a new code:
try:
raise ValueError("underlying issue")
except ValueError as ve:
try:
no(500, ve) # Raises a no.xcpt with both 500 and linked ValueError
except no.xcpt as e:
print(e)
Linking Underlying Exceptions
Add an existing exception to a new code without raising immediately:
try:
raise KeyError("missing key")
except KeyError as ke:
no(404, ke, soften=True)
Grouping Multiple Errors
Bundle multiple codes in one go:
try:
no([404, 500])
except ExceptionGroup as eg:
for subexc in eg.exceptions:
print(subexc)
API Reference
no.register(code: int, message: str, soften: bool = False)
Register a new error code.
code: Numeric identifier.
message: Default message for the code.
soften: If True, calling this code won’t raise immediately.
no(code: int | list[int] | Exception, message: str = None, soften: bool = False)
Invoke or raise an error:
Single int: Raise or return a no.xcpt for that code.
list[int]: Raises an ExceptionGroup of all specified codes.
Existing Exception: Links this exception under your codes.
message: Append an extra message to the error.
soften: Suppresses immediate raising for soft usage.
no.xcpt
Base exception type for all registered errors. Inherits rich context and linking support.
Contributing
Contributions are welcome! Please open issues and pull requests on GitHub.
License
This project is licensed under the MIT License. See LICENSE for details.
Authored by Nichola Walch littler.compression@gmail.com
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 noexcept-1.2.0.tar.gz.
File metadata
- Download URL: noexcept-1.2.0.tar.gz
- Upload date:
- Size: 9.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ec65225dc1a3adb4dd9aea4f2cfddd124af26ced24dad30de1cb36508c71ee73
|
|
| MD5 |
f8ad4daa6fee1608765e876bb5cb2bf5
|
|
| BLAKE2b-256 |
96346e6e6a77bc44369d6d77e7060ca9c337236697fe2832ddd00305a127c1be
|
File details
Details for the file noexcept-1.2.0-py3-none-any.whl.
File metadata
- Download URL: noexcept-1.2.0-py3-none-any.whl
- Upload date:
- Size: 9.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0890f3c7298c101fa5e7b3aa886b05fbb9821f22e74e5008d126f2886a8ac881
|
|
| MD5 |
72abfde1f955c4775c2117ed092b88c2
|
|
| BLAKE2b-256 |
b73daeb3559471d89328d0b4a731e2584d36305bce48063db24106e896092e2b
|