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 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

Quick Start

Import the callable exception handler and register your error codes:

from noexcept 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 noexcept import no

try:
    no(404)

except no.xcpt 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.xcpt with 500 as the linked ValueError

    except no.xcpt 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)

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 wont 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


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.2.1.tar.gz (9.6 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.2.1-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for noexcept-1.2.1.tar.gz
Algorithm Hash digest
SHA256 2ddcd6de328475ba49ceadad747b8004f6f5517655e237eb0455a5c3adcddc44
MD5 4988d2116f5160156d5a5fff07a3619a
BLAKE2b-256 f70acb0f27ec1761452199ae992af3122c1c134226c7d3d2ea9b2f8d902ad0cc

See more details on using hashes here.

File details

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

File metadata

  • Download URL: noexcept-1.2.1-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

Hashes for noexcept-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b29a3b6d3bf07f7840a275b1f43280a7d3dbaf82d22edfd5074c76449e35f504
MD5 ab494efde153421a74153d34d38c371e
BLAKE2b-256 ca61f24376e178910639dadf925e613bbb60aea069e3d4710ba53419165fd646

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