Fix YAMLError with unicode

This commit is contained in:
Otto Winter 2019-06-30 12:19:03 +02:00
parent e5485ab650
commit 59091100e4
No known key found for this signature in database
GPG Key ID: DB66C0BE6013F97E

View File

@ -18,7 +18,7 @@ from esphome.components.substitutions import CONF_SUBSTITUTIONS
from esphome.const import CONF_ESPHOME, CONF_PLATFORM, ESP_PLATFORMS
from esphome.core import CORE, EsphomeError # noqa
from esphome.helpers import color, indent
from esphome.py_compat import text_type, IS_PY2
from esphome.py_compat import text_type, IS_PY2, decode_text
from esphome.util import safe_print, OrderedDict
from typing import List, Optional, Tuple, Union # noqa
@ -634,8 +634,13 @@ def _format_vol_invalid(ex, config):
class InvalidYAMLError(EsphomeError):
def __init__(self, base_exc):
try:
base = str(base_exc)
except UnicodeDecodeError:
base = repr(base_exc)
base = decode_text(base)
message = u"Invalid YAML syntax. Please see YAML syntax reference or use an " \
u"online YAML syntax validator:\n\n{}".format(base_exc)
u"online YAML syntax validator:\n\n{}".format(base)
super(InvalidYAMLError, self).__init__(message)
self.base_exc = base_exc
@ -798,7 +803,7 @@ def strip_default_ids(config):
def read_config(verbose):
_LOGGER.info("Reading configuration...")
_LOGGER.info("Reading configuration %s...", CORE.config_path)
try:
res = load_config()
except EsphomeError as err: