Skip to content

Notification: fix choices rendering for INVALID_CHOICE #11190

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions readthedocs/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,22 @@ def catch_validation_error(self, key):
try:
yield
except ConfigValidationError as error:
raise ConfigError(
message_id=error.message_id,
format_values={
# Expand the format values defined when the exception is risen
# with extra ones we have here
format_values = (
error.format_values if hasattr(error, "format_values") else {}
)
format_values.update(
{
"key": key,
"value": error.format_values.get("value"),
"source_file": os.path.relpath(self.source_file, self.base_path),
},
}
)

raise ConfigError(
message_id=error.message_id,
format_values=format_values,
) from error

def pop(self, name, container, default, raise_ex):
Expand Down
3 changes: 3 additions & 0 deletions readthedocs/config/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,9 @@ def test_new_build_config_invalid_tools_version(self):
build.validate()
assert excinfo.value.message_id == ConfigValidationError.INVALID_CHOICE
assert excinfo.value.format_values.get("key") == "build.tools.python"
assert excinfo.value.format_values.get("choices") == ", ".join(
settings.RTD_DOCKER_BUILD_SETTINGS["tools"]["python"].keys()
)

def test_new_build_config(self):
build = get_build_config(
Expand Down