Skip to content

Commit 7880e85

Browse files
humitosstsewd
andauthored
Notification: fix choices rendering for INVALID_CHOICE (#11190)
* 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. * Update readthedocs/config/config.py Co-authored-by: Santos Gallegos <[email protected]> --------- Co-authored-by: Santos Gallegos <[email protected]>
1 parent e441115 commit 7880e85

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

readthedocs/config/config.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,20 @@ 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 = getattr(error, "format_values", {})
118+
format_values.update(
119+
{
118120
"key": key,
119121
"value": error.format_values.get("value"),
120122
"source_file": os.path.relpath(self.source_file, self.base_path),
121-
},
123+
}
124+
)
125+
126+
raise ConfigError(
127+
message_id=error.message_id,
128+
format_values=format_values,
122129
) from error
123130

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

readthedocs/config/tests/test_config.py

Lines changed: 3 additions & 0 deletions
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)