Skip to main content

Classic Error Handling

Пакет предоставляет примитивы для обработки ошибок на уровне приложения.

Установка

pip install classic-error-handling

Использование

Примеры оформления ошибок:

from classic.error_handling import Error, ErrorsList


# Ошибка с пространством имен
class Namespaced(Error):
    namespace = 'some_namespace'


# Наследование пространства имен
class InheritingNamespace(Namespaced):
    pass


# Ошибка с пространством имен и явным кодом
class NamespacedWithCode(Error):
    namespace = 'some_namespace'
    code = 'some_error'


# Ошибка с явным кодом без пространства имен
class WithCode(Error):
    code = 'some_error'


# Ошибка с литеральным сообщением
class WithLiteralMessage(Error):
    message_template = 'some_message'


# Ошибка с шаблоном сообщения
class WithMessageTemplate(Error):
    message_template = 'some_template: {arg}'

Пример использования:

from classic.error_handling import Error, ErrorsList


# Определяем ошибки приложения
class IncorrectState(Error):
    namespace = 'app'
    message_template = 'Некорректное состояние приложения - "{text}"'


class ServiceNotReady(Error):
    namespace = 'app'
    message_template = 'Сервис еще не готов'


# В сервисах:
class SomeService:
    
    def __init__(self):
        self.ready_to_serve = False

    def is_ready(self):
        """Демонстрирует простое использование"""
        if not self.ready_to_serve:
            raise ServiceNotReady()

    def mark_as_ready(self):
        """Демонстрирует использование шаблонов сообщений"""
        if self.ready_to_serve:
            raise IncorrectState(text='Сервис уже готов')
        self.ready_to_serve = True

    def just_give_errors(self):
        """Демонстрирует метод, который может вернуть несколько ошибок"""
        errors = [IncorrectState(text='ошибка 1'), 
                  IncorrectState(text='ошибка 2')]
        raise ErrorsList(*errors)


# Где-то в адаптерах:

service = SomeService()

try:
    service.is_ready()
except Error as error:
    print(f'Приложение ответило с кодом ошибки "{error.code_representation}", '
          f'сообщение: "{error.message}"')

try:
    service.mark_as_ready()
    service.mark_as_ready()
except Error as error:
    print(f'Приложение ответило с кодом ошибки "{error.code_representation}", '
          f'сообщение: "{error.message}"')
    
try:
    service.just_give_errors()
except ErrorsList as errors_list:
    for error in errors_list.errors:
        print(f'Приложение ответило с кодом ошибки "{error.code_representation}", '
              f'сообщение: "{error.message}"')

Metadata

Release files for classic-error-handling 0.2.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for classic-error-handling 0.2.3
File Size Uploaded Provenance
classic_error_handling-0.2.3.tar.gz 4.8 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for classic-error-handling 0.2.3
File Interpreter ABI Platform
classic_error_handling-0.2.3-py3-none-any.whl Python 3 none any Details

Total release size: 9.6 kB

Release files / classic_error_handling-0.2.3.tar.gz

Download URL classic_error_handling-0.2.3.tar.gz
Size 4.8 kB
Tags Source
SHA-256 checksum
How to use checksums
8dad44e70fb99164d76010792800926389bd96b4da6903cca14fa0564330dbd0
BLAKE2b-256 checksum
How to use checksums
fb2b89a10233c899bff2d081c78d4502120a65896dc653a8fa2cf770e41fbd6d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 11, 2025.

Transparency log

Release files / classic_error_handling-0.2.3-py3-none-any.whl

Download URL classic_error_handling-0.2.3-py3-none-any.whl
Size 4.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
43be68d377b803d73bf8eb2a734c41e0721ff7c3d94a5f4f121b7d3702aaf3f3
BLAKE2b-256 checksum
How to use checksums
c12fe2b4fda32a5fc3e030ebd8702a431d25b8f041570d955d1953dba07cb76e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 11, 2025.

Transparency log

Security for classic-error-handling 0.2.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for classic_error_handling-0.2.3.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 11, 2025.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page