Syntax errors in configuration.yaml and other YAML files not detected, files apparently "ignored"?

Making things short: I insert many intentional syntax errors in configuration.yaml or any other YAML file included with

homeassistant:
  packages: !include_dir_merge_named packages/

I go to developer tools, YAML, check configuration (very fast) and everything appear OK.

By the way many other configuration chages I made before this “test” seems not applied. For example I can’t see the effects of some automation and scripts I changed in the last hours in some packages; it’s like if my (actual, applied) configs file were frozen to some previous undefined state.

No warning or error in the log.

HA latest version

It’s seems there was a syntax error in a YAML file of a package, more precisely an escaping/quoting issue with a regular expression inside a template.

In this case the whole package/YAML file is ignored without any error/warning/log and all entities (input, script, automations) become unavailable!

No, they won’t be ignored, they won’t get reloaded. If you have an error in one of your files, the reload or restart of the integration / HA isn’t possible and will be prevented. This applies for packages as well as “normal” files.

If you use “check configuration”, your files (including packages) will get searched for merely syntax errors. Sometimes an unclosed quotation mark can slip through this check. But what this check doesn’t do is checking for logical errors or things like that. This will be done with reloading the integration (automation, script, whatever you find in the menu under the config check). Normally you should get an error, if you try to reload and syntax errors are present.

In theory, the reload that you are starting is stopped, it will be canceled and an error is logged.

If on the other hand you try to restart HA (depending on the method you use, sometimes this will be prevented), there is no chance for a cancellation, and the file will not be parsed, but it should have an error message logged.

So you should investigat why there is no error message in your case. Normally it should work liek that. :slight_smile:

My experience was as described.

A \d in a '-quoted string/regexp inside a "-quoted string/template in an automation section in a package file.

No errors while checking, HA restart not prevented, no errors in log, all automations and scripts defined in the same file were missing. Any giant syntax error in the same or other files not reported.

Took a lot to figure the file and the error.

As far as I know, the configuration check is for detecting YAML syntax errors. It doesn’t check for errors in a Jinja2 template (that’ll be flagged the moment the Jinja2 interpreter attempts to process the invalid template).

I had an experience that appeared similar. A small error in a YAML file passed the HA check with no problems, but I could tell it was an error because the template sensors after it in the file suddenly disappeared.

I concluded that the problem was that YAML is sufficiently weakly typed that it allows things that aren’t valid for HA, but are “valid” YAML. I couldn’t figure out how else to even detect that error, though.

A \d is not an invalid escape sequence inside a "-quoted YAML string? It is in most languages…

By the way there was no way Jinja interprete ever process the template because the whole automation with this error and all automations of the same file disappeared.

It’s very hard to detect and debug errors in HA/YAML. I start to think it’s better to avoid YAML for not-trivial automations.

Post the section containing the error.

If it’s only within a YAML key’s value it’s unlikely to be detected.

FWIW, all of my automations were composed directly in YAML (using the Visual Studio Code editor) including several complex ones.

The UI config checker like you said is very fast, there is a clue there - it isn’t doing what you think it is doing.

If you want to ACTUALLY check the config to make sure Home Assistant will not break after a change - use the Home Assistant CLI:

core check

It will take about 10 times longer to complete than using the UI - but it will show errors like the Home Assistant log would show on startup.