-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
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
Raise and suppress stack trace when reloading yaml fails #102410
Conversation
Hey there @home-assistant/core, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
Hey there @emontnemery, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
b39616e
to
829a234
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ps. This looks to be a better approach than before. But I think it could be simplified by being more specific in what error we are raising.
cf598f2
to
dd02a9b
Compare
dd02a9b
to
4ce71a7
Compare
4ce71a7
to
260133c
Compare
|
homeassistant/config.py
Outdated
if TYPE_CHECKING: | ||
assert isinstance(ex, HomeAssistantError) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was this comment marked as resolved?
homeassistant/config.py
Outdated
config_file: str = "?" | ||
line: int | str = "?" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, so? My point is that we don't need to resolve to a string here. Attach the output of find_annotation
to config_error_messages
instead.
"platform_schema_validator_err": { | ||
"message": "Unknown error validating config for {p_name} platform for {domain} component with PLATFORM_SCHEMA" | ||
}, | ||
"platform_validator_unknown_err": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but why does the user care? I don't see any reason to have both platform_schema_validator_err
and platform_validator_unknown_err
. Please remove one of them.
@@ -1183,36 +1374,6 @@ async def async_check_ha_config_file(hass: HomeAssistant) -> str | None: | |||
return res.error_str | |||
|
|||
|
|||
@callback | |||
def async_notify_setup_error( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was previously called via async_log_schema_error
and async_log_config_validator_error
when processing the configuration.
Processing the configuration no longer calls async_log_schema_error
and async_log_config_validator_error
though, so.
- Do we no longer get persistent notifications during startup of Home Assistant when setup calls
async_process_component_and_handle_errors
? - I think what needs to happen is that setup.py needs to call
async_process_component
instead, and create the needed notifications. - There are other callers to
async_log_schema_error
andasync_log_config_validator_error
where we do not want notifications to be created. Please remove the calls toasync_notify_setup_error
fromasync_log_schema_error
andasync_log_config_validator_error
Since tests pass without these changes, I think a PR adding tests for the current notification behavior is needed and should be merged before this PR is merged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests were added and merged see: #104384
Notifications are now added via setup.py
The split was made.
#102410 (comment) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is starting to look really great, just minor comments 👍
Why are there no modifications to bootstrap.py?
bootstrap.py
calls async_log_schema_error
from here
core/homeassistant/bootstrap.py
Lines 295 to 296 in 91e0a53
conf_util.async_log_schema_error(config_err, core.DOMAIN, core_config, hass) | |
return None |
homeassistant/config.py
Outdated
platform_name: str | ||
config: ConfigType | ||
integration_link: str | None = None | ||
notify: bool = False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove this, setup.py + bootstrap.py should check the translation key to decide if they want to notify or now
Co-authored-by: Erik Montnemery <[email protected]>
It is correct that bootstrap.py was not changed. As it calls A test for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great, thanks a lot @jbouwh 👍
As discussed on discord, we should look into removing the call to async_notify_setup_error
from async_log_schema_error
+ async_log_homeassistant_error
in a follow-up PR.
The requested changes have been implemented
Proposed change
When reloading yaml fails due to in invalid config. Or other known service error we want the service to be able to raise an error and avoid the need to re-raise in the integration code after when a
None
config has been received.In these cases we explictly supply a detailed error message to the user and show it in the UI (translations supported). In these cases a stack trace is not warranted and we only log the stack trace if debug level logging is enabled.
#102592 introduces
ServiceValidationError
which is a subclass ofHomeAssistantError
. This PR introduces exception classConfigValidationError
. When this error is raised on a reload request, it is reraised to aServiceValidationError
.Raising notifications for an invalid config has been moved to setup. In a follow-up PR notifications can be converted to registering issues in the issue registry.
Custom integrations that use
config_util.async_process_component_config
, e.g. to support reloading yaml, might break as this function now returns config and exception information. To process the returned exception informationconfig_util.async_process_component_config
can be used.Another side effect is that calling these methods no longer will send persistent notifications. As correct exception handling should be handled properly in the UI.
To demonstrate the new code it is applied to the MQTT integration and the reload service.
Replaces: #101037 and #101762
Related architectural discussion:
home-assistant/architecture#992
Implementation plan:
Blog post PR: home-assistant/developers.home-assistant#1986
Type of change
Additional information
Checklist
black --fast homeassistant tests
)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest
.requirements_all.txt
.Updated by running
python3 -m script.gen_requirements_all
..coveragerc
.To help with the load of incoming pull requests: