mirror of
https://github.com/home-assistant/core.git
synced 2025-07-29 18:28:14 +02:00
Differentiate between warnings and errors in check_config helper (#102902)
* Differentiate between warnings and errors in check_config helper * Update tests * Treat configuration errors in frontend and its dependencies as errors * Improve test coverage * Address review comments * Improve test coverage * Improve test coverage * Address review comments * Add comment
This commit is contained in:
@ -40,6 +40,7 @@ PATCHES: dict[str, Any] = {}
|
||||
|
||||
C_HEAD = "bold"
|
||||
ERROR_STR = "General Errors"
|
||||
WARNING_STR = "General Warnings"
|
||||
|
||||
|
||||
def color(the_color, *args, reset=None):
|
||||
@ -116,6 +117,18 @@ def run(script_args: list) -> int:
|
||||
dump_dict(config, reset="red")
|
||||
print(color("reset"))
|
||||
|
||||
if res["warn"]:
|
||||
print(color("bold_white", "Incorrect config"))
|
||||
for domain, config in res["warn"].items():
|
||||
domain_info.append(domain)
|
||||
print(
|
||||
" ",
|
||||
color("bold_yellow", domain + ":"),
|
||||
color("yellow", "", reset="yellow"),
|
||||
)
|
||||
dump_dict(config, reset="yellow")
|
||||
print(color("reset"))
|
||||
|
||||
if domain_info:
|
||||
if "all" in domain_info:
|
||||
print(color("bold_white", "Successful config (all)"))
|
||||
@ -160,7 +173,8 @@ def check(config_dir, secrets=False):
|
||||
res: dict[str, Any] = {
|
||||
"yaml_files": OrderedDict(), # yaml_files loaded
|
||||
"secrets": OrderedDict(), # secret cache and secrets loaded
|
||||
"except": OrderedDict(), # exceptions raised (with config)
|
||||
"except": OrderedDict(), # critical exceptions raised (with config)
|
||||
"warn": OrderedDict(), # non critical exceptions raised (with config)
|
||||
#'components' is a HomeAssistantConfig # noqa: E265
|
||||
"secret_cache": {},
|
||||
}
|
||||
@ -215,6 +229,12 @@ def check(config_dir, secrets=False):
|
||||
if err.config:
|
||||
res["except"].setdefault(domain, []).append(err.config)
|
||||
|
||||
for err in res["components"].warnings:
|
||||
domain = err.domain or WARNING_STR
|
||||
res["warn"].setdefault(domain, []).append(err.message)
|
||||
if err.config:
|
||||
res["warn"].setdefault(domain, []).append(err.config)
|
||||
|
||||
except Exception as err: # pylint: disable=broad-except
|
||||
print(color("red", "Fatal error while loading config:"), str(err))
|
||||
res["except"].setdefault(ERROR_STR, []).append(str(err))
|
||||
|
Reference in New Issue
Block a user