Provides primitives for application errors
Project description
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}"')
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
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 classic_error_handling-0.2.3.tar.gz.
File metadata
- Download URL: classic_error_handling-0.2.3.tar.gz
- Upload date:
- Size: 4.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8dad44e70fb99164d76010792800926389bd96b4da6903cca14fa0564330dbd0
|
|
| MD5 |
657216323aae8991556c1587ea67936e
|
|
| BLAKE2b-256 |
fb2b89a10233c899bff2d081c78d4502120a65896dc653a8fa2cf770e41fbd6d
|
Provenance
The following attestation bundles were made for classic_error_handling-0.2.3.tar.gz:
Publisher:
publish.yml on variasov/classic-error-handling
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
classic_error_handling-0.2.3.tar.gz -
Subject digest:
8dad44e70fb99164d76010792800926389bd96b4da6903cca14fa0564330dbd0 - Sigstore transparency entry: 499573450
- Sigstore integration time:
-
Permalink:
variasov/classic-error-handling@5563041aedcae71d765cf59c821ef63ab73e806c -
Branch / Tag:
refs/heads/main - Owner: https://github.com/variasov
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@5563041aedcae71d765cf59c821ef63ab73e806c -
Trigger Event:
push
-
Statement type:
File details
Details for the file classic_error_handling-0.2.3-py3-none-any.whl.
File metadata
- Download URL: classic_error_handling-0.2.3-py3-none-any.whl
- Upload date:
- Size: 4.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
43be68d377b803d73bf8eb2a734c41e0721ff7c3d94a5f4f121b7d3702aaf3f3
|
|
| MD5 |
f743bd11d641e4c47ab04991197305a3
|
|
| BLAKE2b-256 |
c12fe2b4fda32a5fc3e030ebd8702a431d25b8f041570d955d1953dba07cb76e
|
Provenance
The following attestation bundles were made for classic_error_handling-0.2.3-py3-none-any.whl:
Publisher:
publish.yml on variasov/classic-error-handling
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
classic_error_handling-0.2.3-py3-none-any.whl -
Subject digest:
43be68d377b803d73bf8eb2a734c41e0721ff7c3d94a5f4f121b7d3702aaf3f3 - Sigstore transparency entry: 499573484
- Sigstore integration time:
-
Permalink:
variasov/classic-error-handling@5563041aedcae71d765cf59c821ef63ab73e806c -
Branch / Tag:
refs/heads/main - Owner: https://github.com/variasov
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@5563041aedcae71d765cf59c821ef63ab73e806c -
Trigger Event:
push
-
Statement type: