Skip to main content

Exception module for reuse along projects.

Project description

Darca Exception is a powerful and feature-rich Python exception base class designed to enhance error handling in your projects. It integrates seamlessly with darca-log-facility for structured logging, making debugging and error tracking effortless.

🚀 Key Features

  • Generic & Reusable - Works across various projects without modification.

  • Structured Logging - Uses DarcaLogger for clean and consistent logs.

  • Exception Chaining - Captures underlying causes (cause).

  • Metadata Support - Add extra details (metadata).

  • JSON Serialization - Easily convert exceptions to structured JSON.

  • 100% Test Coverage - Ensured via pytest and pytest-cov.

📦 Installation

Darca Exception uses Poetry for dependency management. To install dependencies, use:

make install

This will: - Create a virtual environment (venv) if needed. - Install Poetry and project dependencies.

🚀 Usage

### Raising an Exception You can raise an exception using DarcaException:

from darca_exception import DarcaException

raise DarcaException("Something went wrong", error_code="GENERIC_ERROR")

### Exception Chaining You can chain exceptions using cause:

try:
    1 / 0
except ZeroDivisionError as e:
    raise DarcaException("Math error", error_code="MATH_001", cause=e)

### Structured JSON Output Converting an exception to JSON is simple:

try:
    raise DarcaException("Database failure", error_code="DB_FAIL")
except DarcaException as e:
    print(e.to_dict())

🛠 Development & Testing

### Running Tests To run the test suite and check coverage:

make test

This will: - Run pytest with coverage enabled. - Generate a test coverage report.

### Formatting & Linting To automatically format and check code consistency:

make format

### Checking Before Pushing Before pushing code, always run:

make check

This will: - Format the code. - Run pre-commit hooks. - Execute tests.

📖 Building Documentation

To generate documentation using Sphinx:

make docs

This will: - Build the documentation in docs/build/html/.

🚀 Pre-Commit Hooks

To run pre-commit checks before committing code:

make precommit

This will: - Run linting, formatting, and static analysis. - Prevent common mistakes before pushing code.

🔧 Adding Dependencies

You can dynamically add dependencies using make:

  • Development dependencies (dev group):

    make add-deps group=dev deps="pytest black isort"
  • Production dependencies:

    make add-prod-deps deps="requests pydantic"

🗑 Cleaning Up

To remove the virtual environment and reset dependencies:

make clean

This will: - Remove the Poetry environment. - Delete cache files.

💡 Contributing

Contributions are welcome! You can contribute by:

  • Submitting feature requests

  • Reporting issues

  • Creating pull requests for fixes and enhancements

Before submitting a pull request, make sure to:

  1. Run make check to ensure all checks pass.

  2. Follow code style and formatting guidelines.

📜 License

This project is licensed under the MIT License. See LICENSE for details.

🎉 Final Notes

This project is production-ready and fully tested. 🚀 If you find any issues, feel free to submit a bug report!

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

darca_exception-0.1.1.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

darca_exception-0.1.1-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file darca_exception-0.1.1.tar.gz.

File metadata

  • Download URL: darca_exception-0.1.1.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for darca_exception-0.1.1.tar.gz
Algorithm Hash digest
SHA256 0c6a4d81c3c25af31c49ca9e3bc7a0a90039e87d1237f65daf9295abb60ab8a6
MD5 e21c323b25033edd94aa1f29de9a527e
BLAKE2b-256 a309305728691bf7befcc05aba96e8112e8a6364ea1df2a52c231ee6d18499be

See more details on using hashes here.

Provenance

The following attestation bundles were made for darca_exception-0.1.1.tar.gz:

Publisher: cd.yml on roelkist/darca-exception

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file darca_exception-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for darca_exception-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f28e629a63629d0d7c5375e11add20baed8f30acb85bdd6be742800e8e7e0cf1
MD5 ff3cef7e10b24d48702c264d212f529b
BLAKE2b-256 f85a967ce8602615eb2aa22345cea678b98db1ae6086c7355d83e95d1500844b

See more details on using hashes here.

Provenance

The following attestation bundles were made for darca_exception-0.1.1-py3-none-any.whl:

Publisher: cd.yml on roelkist/darca-exception

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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