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.0.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.0-py3-none-any.whl (14.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: splurge_exceptions-2025.2.0.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.0.tar.gz
Algorithm Hash digest
SHA256 0e7224c13c68d7008c2b6d37e422f11819b1ba69adef41326ca3a92c52768a9d
MD5 af8ba146f9553371eb23649c06909b78
BLAKE2b-256 16da812dc7744e2a704edd7d4ea57d7d2664f703c0ffa0da933f10af6560a931

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for splurge_exceptions-2025.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 91bf7f749f85a024b86cf066d65571a3923ae6e1b408c2770a7650edcb1c0aea
MD5 4f73190cbd5842d04d943c5b910590ed
BLAKE2b-256 c848a9296997c23d8383cefeb04cc7f5bf4d35ea01f88189ffe3009617a0338c

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