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(
    error_code="invalid-email",
    message="Email address format is invalid",
    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(
        error_code="invalid-integer",
        message="Could not parse input as 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(
    error_code="unexpected",
    message="Unexpected error occurred",
)
# 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.0.1.tar.gz (14.0 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.0.1-py3-none-any.whl (13.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: splurge_exceptions-2025.0.1.tar.gz
  • Upload date:
  • Size: 14.0 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.0.1.tar.gz
Algorithm Hash digest
SHA256 7a6066a55b11af7954e343e197e1c5ee62c574aae70471654134c8733ba4ca27
MD5 b42ec8d347e8ca6a301e4b85a6f5ecdb
BLAKE2b-256 7b16d98b5a19d941c415b24e6ab0251d7b1728226f26f3a29e429ad8899a79f0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for splurge_exceptions-2025.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9cbe723269011d31b1e10f4b72e05f74a9b0492ae3e03237b5e8189f00966806
MD5 8c54c66f37724da4b66b50f79ca81c02
BLAKE2b-256 ac96a90d44a5b127c51bee4592e813364201e6077cd05af73666805056cbd0c6

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