mirror of
https://github.com/home-assistant/core.git
synced 2025-04-25 01:38:02 +00:00
Improve formatting of package errors (#104078)
This commit is contained in:
parent
2ff9beb9c9
commit
a78764f000
@ -831,17 +831,11 @@ def _log_pkg_error(
|
|||||||
hass: HomeAssistant, package: str, component: str, config: dict, message: str
|
hass: HomeAssistant, package: str, component: str, config: dict, message: str
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Log an error while merging packages."""
|
"""Log an error while merging packages."""
|
||||||
message = f"Package {package} setup failed. {message}"
|
message_prefix = f"Setup of package '{package}'"
|
||||||
|
if annotation := find_annotation(config, [CONF_CORE, CONF_PACKAGES, package]):
|
||||||
|
message_prefix += f" at {_relpath(hass, annotation[0])}, line {annotation[1]}"
|
||||||
|
|
||||||
pack_config = config[CONF_CORE][CONF_PACKAGES].get(package, config)
|
_LOGGER.error("%s failed: %s", message_prefix, message)
|
||||||
config_file = getattr(pack_config, "__config_file__", None)
|
|
||||||
if config_file:
|
|
||||||
config_file = _relpath(hass, config_file)
|
|
||||||
else:
|
|
||||||
config_file = "?"
|
|
||||||
message += f" (See {config_file}:{getattr(pack_config, '__line__', '?')})."
|
|
||||||
|
|
||||||
_LOGGER.error(message)
|
|
||||||
|
|
||||||
|
|
||||||
def _identify_config_schema(module: ComponentProtocol) -> str | None:
|
def _identify_config_schema(module: ComponentProtocol) -> str | None:
|
||||||
@ -985,7 +979,7 @@ async def merge_packages_config(
|
|||||||
pack_name,
|
pack_name,
|
||||||
comp_name,
|
comp_name,
|
||||||
config,
|
config,
|
||||||
f"Integration {comp_name} cannot be merged. Expected a dict.",
|
f"integration '{comp_name}' cannot be merged, expected a dict",
|
||||||
)
|
)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@ -998,7 +992,10 @@ async def merge_packages_config(
|
|||||||
pack_name,
|
pack_name,
|
||||||
comp_name,
|
comp_name,
|
||||||
config,
|
config,
|
||||||
f"Integration {comp_name} cannot be merged. Dict expected in main config.",
|
(
|
||||||
|
f"integration '{comp_name}' cannot be merged, dict expected in "
|
||||||
|
"main config"
|
||||||
|
),
|
||||||
)
|
)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@ -1009,7 +1006,7 @@ async def merge_packages_config(
|
|||||||
pack_name,
|
pack_name,
|
||||||
comp_name,
|
comp_name,
|
||||||
config,
|
config,
|
||||||
f"Integration {comp_name} has duplicate key '{duplicate_key}'.",
|
f"integration '{comp_name}' has duplicate key '{duplicate_key}'",
|
||||||
)
|
)
|
||||||
|
|
||||||
return config
|
return config
|
||||||
|
@ -100,7 +100,7 @@ async def async_check_ha_config_file( # noqa: C901
|
|||||||
message: str,
|
message: str,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Handle errors from packages."""
|
"""Handle errors from packages."""
|
||||||
message = f"Package {package} setup failed. {message}"
|
message = f"Setup of package '{package}' failed: {message}"
|
||||||
domain = f"homeassistant.packages.{package}.{component}"
|
domain = f"homeassistant.packages.{package}.{component}"
|
||||||
pack_config = core_config[CONF_PACKAGES].get(package, config)
|
pack_config = core_config[CONF_PACKAGES].get(package, config)
|
||||||
result.add_warning(message, domain, pack_config)
|
result.add_warning(message, domain, pack_config)
|
||||||
|
@ -379,8 +379,8 @@ async def test_package_invalid(hass: HomeAssistant) -> None:
|
|||||||
|
|
||||||
warning = CheckConfigError(
|
warning = CheckConfigError(
|
||||||
(
|
(
|
||||||
"Package p1 setup failed. Integration group cannot be merged. Expected a "
|
"Setup of package 'p1' failed: integration 'group' cannot be merged"
|
||||||
"dict."
|
", expected a dict"
|
||||||
),
|
),
|
||||||
"homeassistant.packages.p1.group",
|
"homeassistant.packages.p1.group",
|
||||||
{"group": ["a"]},
|
{"group": ["a"]},
|
||||||
|
@ -312,38 +312,38 @@
|
|||||||
# ---
|
# ---
|
||||||
# name: test_package_merge_error[packages]
|
# name: test_package_merge_error[packages]
|
||||||
list([
|
list([
|
||||||
'Package pack_1 setup failed. Integration adr_0007_1 cannot be merged. Dict expected in main config. (See configuration.yaml:9).',
|
"Setup of package 'pack_1' at configuration.yaml, line 7 failed: integration 'adr_0007_1' cannot be merged, dict expected in main config",
|
||||||
'Package pack_2 setup failed. Integration adr_0007_2 cannot be merged. Expected a dict. (See configuration.yaml:13).',
|
"Setup of package 'pack_2' at configuration.yaml, line 11 failed: integration 'adr_0007_2' cannot be merged, expected a dict",
|
||||||
"Package pack_4 setup failed. Integration adr_0007_3 has duplicate key 'host'. (See configuration.yaml:20).",
|
"Setup of package 'pack_4' at configuration.yaml, line 19 failed: integration 'adr_0007_3' has duplicate key 'host'",
|
||||||
"Package pack_5 setup failed. Integration 'unknown_integration' not found. (See configuration.yaml:23).",
|
"Setup of package 'pack_5' at configuration.yaml, line 22 failed: Integration 'unknown_integration' not found.",
|
||||||
])
|
])
|
||||||
# ---
|
# ---
|
||||||
# name: test_package_merge_error[packages_include_dir_named]
|
# name: test_package_merge_error[packages_include_dir_named]
|
||||||
list([
|
list([
|
||||||
'Package adr_0007_1 setup failed. Integration adr_0007_1 cannot be merged. Dict expected in main config. (See integrations/adr_0007_1.yaml:2).',
|
"Setup of package 'adr_0007_1' at integrations/adr_0007_1.yaml, line 2 failed: integration 'adr_0007_1' cannot be merged, dict expected in main config",
|
||||||
'Package adr_0007_2 setup failed. Integration adr_0007_2 cannot be merged. Expected a dict. (See integrations/adr_0007_2.yaml:2).',
|
"Setup of package 'adr_0007_2' at integrations/adr_0007_2.yaml, line 2 failed: integration 'adr_0007_2' cannot be merged, expected a dict",
|
||||||
"Package adr_0007_3_2 setup failed. Integration adr_0007_3 has duplicate key 'host'. (See integrations/adr_0007_3_2.yaml:1).",
|
"Setup of package 'adr_0007_3_2' at integrations/adr_0007_3_2.yaml, line 1 failed: integration 'adr_0007_3' has duplicate key 'host'",
|
||||||
"Package unknown_integration setup failed. Integration 'unknown_integration' not found. (See integrations/unknown_integration.yaml:2).",
|
"Setup of package 'unknown_integration' at integrations/unknown_integration.yaml, line 2 failed: Integration 'unknown_integration' not found.",
|
||||||
])
|
])
|
||||||
# ---
|
# ---
|
||||||
# name: test_package_merge_exception[packages-error0]
|
# name: test_package_merge_exception[packages-error0]
|
||||||
list([
|
list([
|
||||||
"Package pack_1 setup failed. Integration test_domain caused error: No such file or directory: b'liblibc.a' (See configuration.yaml:4).",
|
"Setup of package 'pack_1' at configuration.yaml, line 3 failed: Integration test_domain caused error: No such file or directory: b'liblibc.a'",
|
||||||
])
|
])
|
||||||
# ---
|
# ---
|
||||||
# name: test_package_merge_exception[packages-error1]
|
# name: test_package_merge_exception[packages-error1]
|
||||||
list([
|
list([
|
||||||
"Package pack_1 setup failed. Integration test_domain caused error: ModuleNotFoundError: No module named 'not_installed_something' (See configuration.yaml:4).",
|
"Setup of package 'pack_1' at configuration.yaml, line 3 failed: Integration test_domain caused error: ModuleNotFoundError: No module named 'not_installed_something'",
|
||||||
])
|
])
|
||||||
# ---
|
# ---
|
||||||
# name: test_package_merge_exception[packages_include_dir_named-error0]
|
# name: test_package_merge_exception[packages_include_dir_named-error0]
|
||||||
list([
|
list([
|
||||||
"Package unknown_integration setup failed. Integration test_domain caused error: No such file or directory: b'liblibc.a' (See integrations/unknown_integration.yaml:1).",
|
"Setup of package 'unknown_integration' at integrations/unknown_integration.yaml, line 1 failed: Integration test_domain caused error: No such file or directory: b'liblibc.a'",
|
||||||
])
|
])
|
||||||
# ---
|
# ---
|
||||||
# name: test_package_merge_exception[packages_include_dir_named-error1]
|
# name: test_package_merge_exception[packages_include_dir_named-error1]
|
||||||
list([
|
list([
|
||||||
"Package unknown_integration setup failed. Integration test_domain caused error: ModuleNotFoundError: No module named 'not_installed_something' (See integrations/unknown_integration.yaml:1).",
|
"Setup of package 'unknown_integration' at integrations/unknown_integration.yaml, line 1 failed: Integration test_domain caused error: ModuleNotFoundError: No module named 'not_installed_something'",
|
||||||
])
|
])
|
||||||
# ---
|
# ---
|
||||||
# name: test_yaml_error[basic]
|
# name: test_yaml_error[basic]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user