Skip to content

Commit 0edc7fa

Browse files
committed
Notification: fix choices rendering for INVALID_CHOICE
While taking a look at #11189 I found that the rendering was broken. I found the `with` + `yield` pattern pretty complex (I have a note about this in the code) and it seems that complexity is confusing enough to make this hard to dealt with. Anyways, I fixed the problem for now and I added a test case. We can come back to refactoring this in the future with more time.
1 parent e441115 commit 0edc7fa

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

readthedocs/config/config.py

+13-4
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,22 @@ def catch_validation_error(self, key):
112112
try:
113113
yield
114114
except ConfigValidationError as error:
115-
raise ConfigError(
116-
message_id=error.message_id,
117-
format_values={
115+
# Expand the format values defined when the exception is risen
116+
# with extra ones we have here
117+
format_values = (
118+
error.format_values if hasattr(error, "format_values") else {}
119+
)
120+
format_values.update(
121+
{
118122
"key": key,
119123
"value": error.format_values.get("value"),
120124
"source_file": os.path.relpath(self.source_file, self.base_path),
121-
},
125+
}
126+
)
127+
128+
raise ConfigError(
129+
message_id=error.message_id,
130+
format_values=format_values,
122131
) from error
123132

124133
def pop(self, name, container, default, raise_ex):

readthedocs/config/tests/test_config.py

+3
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,9 @@ def test_new_build_config_invalid_tools_version(self):
424424
build.validate()
425425
assert excinfo.value.message_id == ConfigValidationError.INVALID_CHOICE
426426
assert excinfo.value.format_values.get("key") == "build.tools.python"
427+
assert excinfo.value.format_values.get("choices") == ", ".join(
428+
settings.RTD_DOCKER_BUILD_SETTINGS["tools"]["python"].keys()
429+
)
427430

428431
def test_new_build_config(self):
429432
build = get_build_config(

0 commit comments

Comments
 (0)