From b89d309c5f779981bd188599818e4c6af8b78c6e Mon Sep 17 00:00:00 2001 From: Waylan Limberg Date: Thu, 12 Jul 2018 13:27:39 -0400 Subject: [PATCH] User friendly YAML parse errors. This provides a clearer error for users who have an invalid config file. Partially addresses #1543. --- docs/about/release-notes.md | 1 + mkdocs/config/base.py | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/docs/about/release-notes.md b/docs/about/release-notes.md index 729c2eca..a78859ca 100644 --- a/docs/about/release-notes.md +++ b/docs/about/release-notes.md @@ -238,6 +238,7 @@ value to the `theme.custom_dir` option and a warning was issued. As of version ### Other Changes and Additions to Version 1.0 +* User friendly YAML parse errors (#1543). * Officially support Python 3.7. * A missing theme configuration file now raises an error. * Empty `extra_css` and `extra_javascript` settings no longer raise a warning. diff --git a/mkdocs/config/base.py b/mkdocs/config/base.py index b19550e3..a3db6abe 100644 --- a/mkdocs/config/base.py +++ b/mkdocs/config/base.py @@ -2,6 +2,7 @@ from __future__ import unicode_literals import logging import os import sys +from yaml import YAMLError from mkdocs import exceptions from mkdocs import utils @@ -129,7 +130,13 @@ class Config(utils.UserDict): self.data.update(patch) def load_file(self, config_file): - return self.load_dict(utils.yaml_load(config_file)) + try: + return self.load_dict(utils.yaml_load(config_file)) + except YAMLError as e: + # MkDocs knows and understands ConfigurationErrors + raise exceptions.ConfigurationError( + "MkDocs encountered as error parsing the configuration file: {}".format(e) + ) def _open_config_file(config_file):