From e0da15a6b65194dce824995213b6bcf7b2b9efb2 Mon Sep 17 00:00:00 2001 From: Artur Shiriev Date: Sat, 14 Jun 2025 12:43:11 +0300 Subject: [PATCH] improve error message for instruments and bootstrappers --- lite_bootstrap/bootstrappers/base.py | 5 +++-- pyproject.toml | 1 + tests/test_free_bootstrap.py | 4 +++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lite_bootstrap/bootstrappers/base.py b/lite_bootstrap/bootstrappers/base.py index 15e4269..7f8f4c3 100644 --- a/lite_bootstrap/bootstrappers/base.py +++ b/lite_bootstrap/bootstrappers/base.py @@ -27,7 +27,8 @@ class BaseBootstrapper(abc.ABC, typing.Generic[ApplicationT]): def __init__(self, bootstrap_config: BaseConfig) -> None: self.is_bootstrapped = False if not self.is_ready(): - raise RuntimeError(self.not_ready_message) + msg = f"{type(self).__name__} is not ready because {self.not_ready_message}" + raise RuntimeError(msg) self.bootstrap_config = bootstrap_config self.instruments = [] @@ -38,7 +39,7 @@ def __init__(self, bootstrap_config: BaseConfig) -> None: continue if not instrument.is_ready(): - logger.info(instrument.not_ready_message) + logger.info(f"{instrument_type.__name__} is not ready, because {instrument.not_ready_message}") continue self.instruments.append(instrument) diff --git a/pyproject.toml b/pyproject.toml index a077c7e..0ba5a79 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -154,6 +154,7 @@ ignore = [ "D213", # "multi-line-summary-second-line" conflicting with D212 "COM812", # flake8-commas "Trailing comma missing" "ISC001", # flake8-implicit-str-concat + "G004", # allow f-strings in logging ] isort.lines-after-imports = 2 isort.no-lines-before = ["standard-library", "local-folder"] diff --git a/tests/test_free_bootstrap.py b/tests/test_free_bootstrap.py index 6ea9a96..f627aa8 100644 --- a/tests/test_free_bootstrap.py +++ b/tests/test_free_bootstrap.py @@ -42,7 +42,9 @@ def test_free_bootstrap_logging_not_ready(log_output: list[EventDict]) -> None: logging_buffer_capacity=0, ), ) - assert log_output == [{"event": "service_debug is True", "log_level": "info"}] + assert log_output == [ + {"event": "LoggingInstrument is not ready, because service_debug is True", "log_level": "info"} + ] @pytest.mark.parametrize(