dummylabs / thewatchman

Home Assistant custom integration to keep track of missing entities and actions in your config files
MIT License
476 stars 20 forks source link

UnicodeDecodeError #54

Closed moridew closed 1 year ago

moridew commented 2 years ago

Hello. Thank you for your kindness.

The following error occurs:

Logger: homeassistant.config_entries Source: custom_components/watchman/utils.py:255 Integration: Watchman (documentation, issues) First occurred: 11:19:42 (1 occurrences) Last logged: 11:19:42

Error setting up entry Watchman for watchman Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/config_entries.py", line 339, in async_setup result = await component.async_setup_entry(hass, self) File "/config/custom_components/watchman/init.py", line 137, in async_setup_entry parse_config(hass, reason="changes in watchman configuration") File "/config/custom_components/watchman/init.py", line 345, in parse_config entity_list, service_list, files_parsed, files_ignored = parse( File "/config/custom_components/watchman/utils.py", line 255, in parse for i, line in enumerate(open(yaml_file, encoding="utf-8")): File "/usr/local/lib/python3.9/codecs.py", line 322, in decode (result, consumed) = self._buffer_decode(data, self.errors, final) UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb4 in position 32: invalid start byte

Opontios commented 1 year ago

Same thing here. Any way to resolve?

Logger: homeassistant
Source: custom_components/watchman/utils.py:255
Integration: Watchman ([documentation](https://github.com/dummylabs/thewatchman), [issues](https://github.com/dummylabs/thewatchman/issues))
First occurred: 15:09:52 (1 occurrences)
Last logged: 15:09:52
Error doing job: Task exception was never retrieved

Traceback (most recent call last):
  File "/config/custom_components/watchman/__init__.py", line 268, in async_on_home_assistant_started
    parse_config(hass, reason="HA restart")
  File "/config/custom_components/watchman/__init__.py", line 345, in parse_config
    entity_list, service_list, files_parsed, files_ignored = parse(
  File "/config/custom_components/watchman/utils.py", line 255, in parse
    for i, line in enumerate(open(yaml_file, encoding="utf-8")):
  File "/usr/local/lib/python3.10/codecs.py", line 322, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xed in position 108: invalid continuation byte 
moridew commented 1 year ago

An error occurs when the annotation is utf8. The utf8 annotation has been deleted and normalized.

Opontios commented 1 year ago

What exactly is the annotation?

moridew commented 1 year ago

You had to comment all .yaml files in English only. All yaml files in the subdirectory, including files in the config folder.

dummylabs commented 1 year ago

Any other language should work fine for comments, not just English. The important condition is to explicitly save file with UTF-8 encoding in your text editor. I've added a yaml file with UTF-8 comments to the automated tests, it works just fine with current version (0.6.0)

On top of that, starting from 0.6.1 (not yet released) files with encodings other than UTF-8 will not cause Watchman to crash, it will report error message to the log instead.