mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-09 10:16:29 +00:00
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:
parent
70685c41be
commit
fa9b3b939e
@ -87,9 +87,6 @@ def api_process_raw(content):
|
||||
|
||||
def api_return_error(message=None):
|
||||
"""Return a API error message."""
|
||||
if message:
|
||||
_LOGGER.error(message)
|
||||
|
||||
return web.json_response({
|
||||
JSON_RESULT: RESULT_ERROR,
|
||||
JSON_MESSAGE: message,
|
||||
|
@ -103,15 +103,15 @@ class DockerHomeAssistant(DockerBase):
|
||||
)
|
||||
|
||||
# wait until command is done
|
||||
container.wait()
|
||||
exit_code = container.wait()
|
||||
output = container.logs()
|
||||
|
||||
except docker.errors.DockerException as err:
|
||||
_LOGGER.error("Can't execute command -> %s", err)
|
||||
return b""
|
||||
return (None, b"")
|
||||
|
||||
# cleanup container
|
||||
with suppress(docker.errors.DockerException):
|
||||
container.remove(force=True)
|
||||
|
||||
return output
|
||||
return (exit_code, output)
|
||||
|
@ -13,7 +13,7 @@ from .validate import SCHEMA_HASS_CONFIG
|
||||
|
||||
_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):
|
||||
@ -171,17 +171,16 @@ class HomeAssistant(JsonConfig):
|
||||
|
||||
async def check_config(self):
|
||||
"""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"
|
||||
)
|
||||
|
||||
# if not valid
|
||||
if not log:
|
||||
if exit_code is None:
|
||||
return (False, "")
|
||||
|
||||
# parse output
|
||||
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 (True, log)
|
||||
|
Loading…
x
Reference in New Issue
Block a user