Use exit code to detect wrong configs (#156)

* Update homeassistant.py

* Update homeassistant.py

* Update util.py

* add support for yaml errors
This commit is contained in:
Pascal Vizeli 2017-08-16 11:25:38 +02:00 committed by GitHub
parent 70685c41be
commit fa9b3b939e
3 changed files with 7 additions and 11 deletions

View File

@ -87,9 +87,6 @@ def api_process_raw(content):
def api_return_error(message=None): def api_return_error(message=None):
"""Return a API error message.""" """Return a API error message."""
if message:
_LOGGER.error(message)
return web.json_response({ return web.json_response({
JSON_RESULT: RESULT_ERROR, JSON_RESULT: RESULT_ERROR,
JSON_MESSAGE: message, JSON_MESSAGE: message,

View File

@ -103,15 +103,15 @@ class DockerHomeAssistant(DockerBase):
) )
# wait until command is done # wait until command is done
container.wait() exit_code = container.wait()
output = container.logs() output = container.logs()
except docker.errors.DockerException as err: except docker.errors.DockerException as err:
_LOGGER.error("Can't execute command -> %s", err) _LOGGER.error("Can't execute command -> %s", err)
return b"" return (None, b"")
# cleanup container # cleanup container
with suppress(docker.errors.DockerException): with suppress(docker.errors.DockerException):
container.remove(force=True) container.remove(force=True)
return output return (exit_code, output)

View File

@ -13,7 +13,7 @@ from .validate import SCHEMA_HASS_CONFIG
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
RE_CONFIG_CHECK = re.compile(r"error", re.IGNORECASE) RE_YAML_ERROR = re.compile(r"homeassistant\.util\.yaml")
class HomeAssistant(JsonConfig): class HomeAssistant(JsonConfig):
@ -171,17 +171,16 @@ class HomeAssistant(JsonConfig):
async def check_config(self): async def check_config(self):
"""Run homeassistant config check.""" """Run homeassistant config check."""
log = await self.docker.execute_command( exit_code, log = await self.docker.execute_command(
"python3 -m homeassistant -c /config --script check_config" "python3 -m homeassistant -c /config --script check_config"
) )
# if not valid # if not valid
if not log: if exit_code is None:
return (False, "") return (False, "")
# parse output # parse output
log = convert_to_ascii(log) log = convert_to_ascii(log)
if RE_CONFIG_CHECK.search(log): if exit_code != 0 or RE_YAML_ERROR.search(log):
return (False, log) return (False, log)
return (True, log) return (True, log)