Skip to content

Commit 624b63f

Browse files
authored
Merge pull request #38 from modern-python/36-feature-add-more-intuitive-messages-about-instruments-state
improve error message for instruments and bootstrappers
2 parents 863d160 + e0da15a commit 624b63f

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

lite_bootstrap/bootstrappers/base.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ class BaseBootstrapper(abc.ABC, typing.Generic[ApplicationT]):
2727
def __init__(self, bootstrap_config: BaseConfig) -> None:
2828
self.is_bootstrapped = False
2929
if not self.is_ready():
30-
raise RuntimeError(self.not_ready_message)
30+
msg = f"{type(self).__name__} is not ready because {self.not_ready_message}"
31+
raise RuntimeError(msg)
3132

3233
self.bootstrap_config = bootstrap_config
3334
self.instruments = []
@@ -38,7 +39,7 @@ def __init__(self, bootstrap_config: BaseConfig) -> None:
3839
continue
3940

4041
if not instrument.is_ready():
41-
logger.info(instrument.not_ready_message)
42+
logger.info(f"{instrument_type.__name__} is not ready, because {instrument.not_ready_message}")
4243
continue
4344

4445
self.instruments.append(instrument)

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ ignore = [
154154
"D213", # "multi-line-summary-second-line" conflicting with D212
155155
"COM812", # flake8-commas "Trailing comma missing"
156156
"ISC001", # flake8-implicit-str-concat
157+
"G004", # allow f-strings in logging
157158
]
158159
isort.lines-after-imports = 2
159160
isort.no-lines-before = ["standard-library", "local-folder"]

tests/test_free_bootstrap.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ def test_free_bootstrap_logging_not_ready(log_output: list[EventDict]) -> None:
4242
logging_buffer_capacity=0,
4343
),
4444
)
45-
assert log_output == [{"event": "service_debug is True", "log_level": "info"}]
45+
assert log_output == [
46+
{"event": "LoggingInstrument is not ready, because service_debug is True", "log_level": "info"}
47+
]
4648

4749

4850
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)