Skip to main content

The standardized exception framework for Splurge projects.

Project description

Splurge Exceptions

PyPI version Python versions License: MIT

CI Coverage Ruff mypy

A comprehensive Python exception management library that provides structured error handling, semantic error codes, and intelligent error organization for Splurge projects.

Quick Start

Installation

pip install splurge-exceptions

Basic Usage

1. Create Structured Exceptions

from splurge_exceptions import SplurgeValueError

# Create a semantic exception with context
error = SplurgeValueError(
    "Email address format is invalid",
    error_code="invalid-email",
    details={"provided": "user@", "expected": "user@domain.com"}
)

# Attach context and suggestions
error.attach_context("user_id", 12345)
error.add_suggestion("Use format: username@domain.com")
error.add_suggestion("Verify domain is included")

# Full error code: "splurge.value.invalid-email"
print(error.full_code)

2. Convert Exceptions with Chaining

from splurge_exceptions import SplurgeValueError

try:
    # Some operation that might fail
    int("invalid")
except ValueError as e:
    # Wrap the exception with structured error
    wrapped = SplurgeValueError(
        "Could not parse input as integer",
        error_code="invalid-integer",
        details={"input": "invalid"}
    )
    raise wrapped from e

3. Format Errors for Users

from splurge_exceptions import ErrorMessageFormatter

formatter = ErrorMessageFormatter()
formatted = formatter.format_error(
    error,
    include_context=True,
    include_suggestions=True,
)
print(formatted)

4. Integration Support for Splurge Family Libraries

from splurge_exceptions import SplurgeFrameworkError

class SplurgeSafeIoError(SplurgeFrameworkError):
    _domain = "splurge-safe-io"

class SplurgeSafeIoRuntimeError(SplurgeSafeIoError):
    _domain = "splurge-safe-io.runtime"

raise SplurgeSafeIoRuntimeError(
    "Unexpected error occurred",
    error_code="unexpected",
)
# Resulting full error code: "splurge-safe-io.runtime.unexpected"

Key Features

🎯 Semantic Error Codes - Hierarchical error codes with domain organization
Exception Chaining - Preserve exception chains with raise ... from
📋 Context Attachment - Add operation context and recovery suggestions
Message Formatting - Beautiful, structured error message output
Type Safe - Full type annotations with MyPy strict mode support
🎭 Framework Extensions - Clean extension points for domain-specific exceptions

Exception Types

Splurge Exceptions provides 9 exception types for different error scenarios:

  • SplurgeError - Base exception class
  • SplurgeValueError - Input validation errors
  • SplurgeOSError - Operating system errors
  • SplurgeRuntimeError - Runtime execution errors
  • SplurgeTypeError - Type errors
  • SplurgeAttributeError - Missing object attributes/methods
  • SplurgeImportError - Module import failures
  • SplurgeLookupError - Lookup errors
  • SplurgeFrameworkError - Framework-level errors
  • SplurgeSubclassError - Framework misconfiguration errors (used internally)

Documentation

Project Structure

splurge-exceptions/
├── splurge_exceptions/          # Main package
│   ├── core/                    # Core exceptions and error codes
│   ├── formatting/              # Message formatting utilities
│   ├── context/                 # Context utilities
│   └── cli.py                   # CLI interface
├── tests/                       # Test suite (130+ tests)
│   ├── unit/                    # Unit tests
│   └── integration/             # Integration tests
└── docs/                        # Documentation

Testing

The library includes comprehensive test coverage:

  • 130 tests - Unit tests (100% passing)
  • 94% code coverage - All public APIs tested
  • MyPy strict mode - Full type safety validation
  • Ruff linting - Code quality enforcement

Run tests:

pytest tests/
pytest tests/ --cov=splurge_exceptions --cov-report=html

License

MIT License - See LICENSE file for details

Author

Jim Schilling

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

splurge_exceptions-2025.2.2.tar.gz (14.7 kB view details)

Uploaded Source

Built Distribution

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

splurge_exceptions-2025.2.2-py3-none-any.whl (14.3 kB view details)

Uploaded Python 3

File details

Details for the file splurge_exceptions-2025.2.2.tar.gz.

File metadata

  • Download URL: splurge_exceptions-2025.2.2.tar.gz
  • Upload date:
  • Size: 14.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for splurge_exceptions-2025.2.2.tar.gz
Algorithm Hash digest
SHA256 b67138cad1c48d6ab5feaf610c520d3c21740cf68a8fb2840593f521ec61d852
MD5 9cb6fc8888f8b3fa014b2bed6855507c
BLAKE2b-256 27af0e4f0f6f20be14b511b3a5c4b5d5e7e0a86dcae6e5954ab02951bb7dab9d

See more details on using hashes here.

File details

Details for the file splurge_exceptions-2025.2.2-py3-none-any.whl.

File metadata

File hashes

Hashes for splurge_exceptions-2025.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 298588a40fb1752e6122f783af3cfa8936768397852a06f6f68a6fb4bb0fcb39
MD5 b1d73410ee9fed7c55b4c40f168ff448
BLAKE2b-256 32db591867845fe0e0b80fd2d74c464f1f342de83469b04ef1a249b2eed83784

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