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.0.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.0-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: darca_exception-0.1.0.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.0.tar.gz
Algorithm Hash digest
SHA256 e72905279efc07a15c2248c4dcb25ab25204520129ce400773a1c94e2d2efd8d
MD5 3b2d1a3af55105e98f1327a6b1444ed4
BLAKE2b-256 07d7972bc7972a5b1fb3d0ccaca7345e2be0fffae3e89a672a8c928b43056bb9

See more details on using hashes here.

Provenance

The following attestation bundles were made for darca_exception-0.1.0.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.0-py3-none-any.whl.

File metadata

File hashes

Hashes for darca_exception-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9fb2c4fae92da5397de16ffcaf3253d95d5d7fa458ba9eb1b496e6466bafd7ae
MD5 f8a43a082d0d018a0681fbd34d32c57b
BLAKE2b-256 5bd4ae53845d22b93d4561dc5d095a901f9069293413b2b41280548a74f96da2

See more details on using hashes here.

Provenance

The following attestation bundles were made for darca_exception-0.1.0-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