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.3.1.tar.gz (15.2 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.3.1-py3-none-any.whl (14.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: splurge_exceptions-2025.3.1.tar.gz
  • Upload date:
  • Size: 15.2 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.3.1.tar.gz
Algorithm Hash digest
SHA256 ddb9eb665db310920da41c7da4ac339a4dc685f318572e53a579dd0a001c1ce3
MD5 6f56c470dfd92633a831a8793ec64630
BLAKE2b-256 1cd95ee0c8f7f718887d7a7bcbbc70aa8abad85890c71b6e3cfb5a830fba6b41

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for splurge_exceptions-2025.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 41fe250ed17e550e02d894c73b6e762d5ae7017a78e97101baa2451c72bd31cd
MD5 04385bed46dc9a646e760c09193ad015
BLAKE2b-256 ffa56f76ea6e46a32fe5cb3b0b2cb08ea93041a0868192db75a4160df2d5a945

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