Skip to content

Commit

Permalink
Stop config validation after the first error (#3437)
Browse files Browse the repository at this point in the history
If one config option completely fails validation, that means its value remains "raw" from YAML, which can cause unpredictable errors when validating other options that might look at the value. Instead just decide one error is enough.
  • Loading branch information
oprypin committed Oct 25, 2023
1 parent 49d02e4 commit b5250bf
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion mkdocs/config/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ def _validate(self) -> tuple[ConfigErrors, ConfigWarnings]:
config_option.reset_warnings()
except ValidationError as e:
failed.append((key, e))
break

for key in set(self.keys()) - self._schema_keys:
warnings.append((key, f"Unrecognised configuration name: {key}"))
Expand Down Expand Up @@ -382,7 +383,7 @@ def load_config(
log.debug(f"Config value '{key}' = {value!r}")

if len(errors) > 0:
raise exceptions.Abort(f"Aborted with {len(errors)} configuration errors!")
raise exceptions.Abort("Aborted with a configuration error!")
elif cfg.strict and len(warnings) > 0:
raise exceptions.Abort(
f"Aborted with {len(warnings)} configuration warnings in 'strict' mode!"
Expand Down

0 comments on commit b5250bf

Please sign in to comment.