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.1.0.tar.gz (14.4 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.1.0-py3-none-any.whl (14.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: splurge_exceptions-2025.1.0.tar.gz
  • Upload date:
  • Size: 14.4 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.1.0.tar.gz
Algorithm Hash digest
SHA256 e2b1759bfc394109b23e424e21ee7de1010d2bae0537b18c25dcb879b6e0c88e
MD5 69f0adfcddfd00d72bc93560ff7c5993
BLAKE2b-256 0976f1446f75fb67e3732d32b0a381cf36c44e2fde98780bc7566d7a1f36a72b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for splurge_exceptions-2025.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5e7c42dafc3ef9cfcc5e77ad31712df52a34482aa42d27c7f49311e2bdbcc9bb
MD5 1f5027ec2d765715fb1a6a7039d43076
BLAKE2b-256 fe8c1afeb6f6ac2d925a8bf472b7e82fe9c89bc7d64ca14ed825b62acef45a28

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