mirror of
https://github.com/Chia-Network/chia-blockchain.git
synced 2026-08-28 18:14:19 -05:00
* Enable PEP604 Ruff rules * Fix harcoded signature in test * Hack CLVMStreamable test with note to fast follow
32 lines
751 B
Python
32 lines
751 B
Python
# Package: utils
|
|
|
|
from __future__ import annotations
|
|
|
|
import logging
|
|
import traceback
|
|
from collections.abc import Iterator
|
|
from contextlib import contextmanager
|
|
|
|
|
|
@contextmanager
|
|
def log_exceptions(
|
|
log: logging.Logger,
|
|
*,
|
|
consume: bool = False,
|
|
message: str = "Caught exception",
|
|
level: int = logging.ERROR,
|
|
show_traceback: bool = True,
|
|
exceptions_to_process: type[BaseException] | tuple[type[BaseException], ...] = Exception,
|
|
) -> Iterator[None]:
|
|
try:
|
|
yield
|
|
except exceptions_to_process as e:
|
|
message = f"{message}: {type(e).__name__}: {e}"
|
|
if show_traceback:
|
|
message += f"\n{traceback.format_exc()}"
|
|
|
|
log.log(level, message)
|
|
|
|
if not consume:
|
|
raise
|