Robust error handling and exception management for Python
Project description
PyError
A robust error handling and exception management library for Python. PyError provides utilities for logging and raising exceptions with flexible exception types, error codes, and custom parameters.
Features
- Flexible Exception Handling: Support for custom exceptions with configurable error codes and additional parameters.
- Logging Integration: Integrated logging via
flashloggerfor fatal, critical, and error levels. - Positional and Keyword Arguments: Support for passing additional arguments (
*args) and keyword arguments (**kwargs) to exceptions. - Multiple Exception Types: Functions for fatal, critical, and error scenarios with consistent interfaces.
- Easy Extension: Extensible design allowing custom exception classes with complex initialization logic.
Installation
Install from PyPI:
pip install PyError
Or clone the repository and install locally:
git clone https://github.com/kingkybel/PyError.git
cd PyError
pip install .
Usage
Fatal Errors
from error import fatal
# Raise a fatal error with default SystemExit
fatal("Critical system failure")
# Raise a fatal error with custom error code
fatal("Database connection failed", error_code=2)
# Raise a custom exception
class DatabaseError(Exception):
def __init__(self, code, *args, **kwargs):
self.code = code
super().__init__(*args, **kwargs)
fatal("Connection timeout", exception=DatabaseError, error_code=42)
Critical Errors
from error import critical
# Raise a critical error
critical("Authentication failed")
# With custom exception
critical("Invalid configuration", exception=ConfigError, error_code=10)
Standard Errors
from error import error
# Raise an error
error("File not found")
# With additional parameters
error("Operation failed", exception=OperationError, error_code=1)
Advanced Usage
Custom Exceptions with Extra Parameters
from error import fatal
class AppError(Exception):
def __init__(self, code, *args, **kwargs):
self.code = code
self.context = kwargs.get('context')
self.timestamp = kwargs.get('timestamp')
# Pass extra keyword arguments
fatal("App failed", AppError, 5, context="user_login", timestamp="2026-05-04")
Testing
Run the test suite:
python -m unittest PyError.test.test_error
Or with verbose output:
python -m unittest PyError.test.test_error -v
Requirements
kingkybel-pyfundamentalskingkybel-pyflashlogger
License
See LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit pull requests or open issues for bugs and feature requests.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file kingkybel_pyerror-0.1.1.tar.gz.
File metadata
- Download URL: kingkybel_pyerror-0.1.1.tar.gz
- Upload date:
- Size: 3.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d7cfecfe865e249d618baecf142cadb4ff5a6a49b6f8503084ee069a9b660231
|
|
| MD5 |
37ce8c4b0bfe382eb0244f1376f946c7
|
|
| BLAKE2b-256 |
d85dfa13cdf53c8ed02d80215de1caafed3e840826ed5e9ba0adc1a505900158
|
File details
Details for the file kingkybel_pyerror-0.1.1-py3-none-any.whl.
File metadata
- Download URL: kingkybel_pyerror-0.1.1-py3-none-any.whl
- Upload date:
- Size: 2.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9d1b69e8d4431385aa4242efa0c9d0ba84701d95b99061a4087fb5350ef70bfd
|
|
| MD5 |
a6dc77920b9c983d25a8dfa54cfab8e9
|
|
| BLAKE2b-256 |
bc0762fc169dd05e4d034b458c9ed212919e6a113e0babd12554d17afc0d1048
|