Skip to main content

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 complaints 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, complaints, linked exceptions, and stack traces when converting to string.

Installation

Requires Python 3.11 or newer.

With PIP

pip install noexcept

With GitHub

pip install git+https://github.com/HiDrNikki/noexcept.git

pip install git+https://github.com/HiDrNikki/noexcept.git@v1.2.2

pip install -e git+https://github.com/HiDrNikki/noexcept.git@main#egg=noexcept

Quick Start

Import the callable exception handler and register your error codes:

from noexcept import no

Register codes at startup

no.likey(404, "Not Found")            # Standard error
no.likey(500, "Server Error")         # Standard error
no.likey(123, "Soft Error", soft=True)  # Soft (non-raising)

Raising an Exception

from noexcept import no

try:
    no(404)
except no.way as noexcept:
    print(str(noexcept))
    # [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.way with 500 as the linked ValueError
    except no.way as noexcept:
        print(noexcept)

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)

no.go

no.go provides a context manager for cleanly handling exceptions:

with no.go(404):
    raise ValueError("Original issue")  # Automatically wrapped under code 404

It can also be used in line to run a callable, and raise an error code if it fails.

result = no.go(404, myFunction, *args, **kwargs, soften = True)

In both cases the raw error that is thrown is linked to whatever code is passed.

no.bueno

no.bueno indicates if any soft errors have yet been registered:

no(123)
if not no.bueno:
    print("Issues detected")

no.nos

no.nos contains details of all registered error codes:

print(no.nos)
# {404: 'Not Found', 500: 'Server Error', 123: 'Soft Error'}

no.complaints

no.complaints accumulates soft error messages:

no(123)
no(123, "Extra warning detail")

print(no.complaints)
# ['Soft Error', 'Soft Error: Extra warning detail']

API Reference

Import the handler

from noexcept import no

Register error codes

no.likey(code: int, complaint: str, soften: bool = False)

Raise exceptions

no(code: int | list[int] | Exception, complaint: str = None, soften: bool = False)

Base exception type

no.way

Inline error safe code execution, or context manager

no.go

A boolean indicating whether any soft errors have been triggered yet

no.bueno

A dictionary containing all the currently triggered codes

no.nos

A flat list of all of the error messages

no.complaints

Clears the pending exception, along with all codes and messages

no.dice()

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

noexcept-1.3.1.tar.gz (13.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

noexcept-1.3.1-py3-none-any.whl (13.3 kB view details)

Uploaded Python 3

File details

Details for the file noexcept-1.3.1.tar.gz.

File metadata

  • Download URL: noexcept-1.3.1.tar.gz
  • Upload date:
  • Size: 13.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.0

File hashes

Hashes for noexcept-1.3.1.tar.gz
Algorithm Hash digest
SHA256 1081c11d1afa0999e7902e2560c7fea03d7cd20b8461f881589e03f751dfe8ec
MD5 49f8cf815848c3cfd95c06766d562890
BLAKE2b-256 16d84700ccd100c9ef0ce9df38f847a25489c1bdf9f9019708d5268fd8a925af

See more details on using hashes here.

File details

Details for the file noexcept-1.3.1-py3-none-any.whl.

File metadata

  • Download URL: noexcept-1.3.1-py3-none-any.whl
  • Upload date:
  • Size: 13.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.0

File hashes

Hashes for noexcept-1.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8f7760900e7267c2d2b582f0b1094470f2e9ebed99facc98a77996a349214e3b
MD5 87b1185fb1329c82239a840ecc365b2e
BLAKE2b-256 16ea5f8cd7a86e0c425d8747d6aff9b73b112923527b519812bd8c9e6bf50c4a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page