Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not notify config errors during logging #104466

Merged
merged 2 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions homeassistant/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
DATA_SETUP,
DATA_SETUP_STARTED,
DATA_SETUP_TIME,
async_notify_setup_error,
async_set_domains_to_be_loaded,
async_setup_component,
)
Expand Down Expand Up @@ -293,6 +294,7 @@ async def async_from_config_dict(
await conf_util.async_process_ha_core_config(hass, core_config)
except vol.Invalid as config_err:
conf_util.async_log_schema_error(config_err, core.DOMAIN, core_config, hass)
async_notify_setup_error(hass, core.DOMAIN)
return None
except HomeAssistantError:
_LOGGER.error(
Expand Down
7 changes: 6 additions & 1 deletion homeassistant/components/device_tracker/legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@
)
from homeassistant.helpers.restore_state import RestoreEntity
from homeassistant.helpers.typing import ConfigType, GPSType, StateType
from homeassistant.setup import async_prepare_setup_platform, async_start_setup
from homeassistant.setup import (
async_notify_setup_error,
async_prepare_setup_platform,
async_start_setup,
)
from homeassistant.util import dt as dt_util
from homeassistant.util.yaml import dump

Expand Down Expand Up @@ -1007,6 +1011,7 @@ async def async_load_config(
device["dev_id"] = cv.slugify(dev_id)
except vol.Invalid as exp:
async_log_schema_error(exp, dev_id, devices, hass)
async_notify_setup_error(hass, DOMAIN)
else:
result.append(Device(hass, **device))
return result
Expand Down
6 changes: 5 additions & 1 deletion homeassistant/components/template/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@
from homeassistant.components.weather import DOMAIN as WEATHER_DOMAIN
from homeassistant.config import async_log_schema_error, config_without_domain
from homeassistant.const import CONF_BINARY_SENSORS, CONF_SENSORS, CONF_UNIQUE_ID
from homeassistant.core import HomeAssistant
from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.trigger import async_validate_trigger_config
from homeassistant.helpers.typing import ConfigType
from homeassistant.setup import async_notify_setup_error

from . import (
binary_sensor as binary_sensor_platform,
Expand Down Expand Up @@ -64,7 +67,7 @@
)


async def async_validate_config(hass, config):
async def async_validate_config(hass: HomeAssistant, config: ConfigType) -> ConfigType:
"""Validate config."""
if DOMAIN not in config:
return config
Expand All @@ -81,6 +84,7 @@ async def async_validate_config(hass, config):
)
except vol.Invalid as err:
async_log_schema_error(err, DOMAIN, cfg, hass)
async_notify_setup_error(hass, DOMAIN)
continue

legacy_warn_printed = False
Expand Down
5 changes: 0 additions & 5 deletions homeassistant/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
from .helpers.typing import ConfigType
from .loader import ComponentProtocol, Integration, IntegrationNotFound
from .requirements import RequirementsNotFound, async_get_integration_with_requirements
from .setup import async_notify_setup_error
from .util.package import is_docker_env
from .util.unit_system import get_unit_system, validate_unit_system
from .util.yaml import SECRET_YAML, Secrets, load_yaml
Expand Down Expand Up @@ -549,8 +548,6 @@ def async_log_schema_error(
link: str | None = None,
) -> None:
"""Log a schema validation error."""
if hass is not None:
async_notify_setup_error(hass, domain, link)
message = format_schema_error(hass, ex, domain, config, link)
_LOGGER.error(message)

Expand All @@ -568,8 +565,6 @@ def async_log_config_validator_error(
async_log_schema_error(ex, domain, config, hass, link)
return

if hass is not None:
async_notify_setup_error(hass, domain, link)
message = format_homeassistant_error(hass, ex, domain, config, link)
_LOGGER.error(message, exc_info=ex)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ async def test_setup_hass_invalid_core_config(
event_loop: asyncio.AbstractEventLoop,
) -> None:
"""Test it works."""
with patch("homeassistant.config.async_notify_setup_error") as mock_notify:
with patch("homeassistant.bootstrap.async_notify_setup_error") as mock_notify:
hass = await bootstrap.async_setup_hass(
runner.RuntimeConfig(
config_dir=get_test_config_dir(),
Expand Down