hacs / integration

HACS gives you a powerful UI to handle downloads of all your custom needs.
https://hacs.xyz
MIT License
5.2k stars 1.26k forks source link

[Feature Request] Separate list of installed repositories for recovery from hacs.repository corruption #3506

Closed rct closed 7 months ago

rct commented 7 months ago

System Health details

System Information

version core-2024.1.6
installation_type Home Assistant OS
dev false
hassio true
docker true
user root
virtualenv false
python_version 3.11.6
os_name Linux
os_version 6.1.59
arch x86_64
timezone America/New_York
config_dir /config
Home Assistant Community Store GitHub API | ok -- | -- GitHub Content | ok GitHub Web | ok GitHub API Calls Remaining | 5000 Installed Version | 1.34.0 Stage | running Available Repositories | 853 Downloaded Repositories | 1
AccuWeather can_reach_server | ok -- | -- remaining_requests | 47
Home Assistant Cloud logged_in | true -- | -- subscription_expiration | May 24, 2024 at 8:00 PM relayer_connected | true relayer_region | us-east-1 remote_enabled | true remote_connected | true alexa_enabled | true google_enabled | true remote_server | us-east-1-3.ui.nabu.casa certificate_status | ready instance_id | ab6ffa1d7b754c2bb359ce96876a25e1 can_reach_cert_server | ok can_reach_cloud_auth | ok can_reach_cloud | ok
Home Assistant Supervisor host_os | Home Assistant OS 11.1 -- | -- update_channel | stable supervisor_version | supervisor-2024.01.1 agent_version | 1.6.0 docker_version | 24.0.6 disk_total | 63.0 GB disk_used | 47.9 GB healthy | true supported | true board | ova supervisor_api | ok version_api | ok installed_addons | Advanced SSH & Web Terminal (17.0.4), Grafana (9.1.3), Mosquitto broker (6.4.0), Plex Media Server (3.3.2), Z-Wave JS UI (3.3.1), Zigbee2MQTT (1.35.2-1), UniFi Controller (0.18.1), Studio Code Server (5.15.0), eufy-security-ws (1.7.1)
Dashboards dashboards | 7 -- | -- resources | 3 views | 41 mode | storage
Recorder oldest_recorder_run | February 6, 2024 at 5:56 PM -- | -- current_recorder_run | February 11, 2024 at 8:01 PM estimated_db_size | 1992.78 MiB database_engine | sqlite database_version | 3.41.2

Checklist

Describe the issue

It appears If hacs.repositories becomes corrupted, HACS loses track of what has been installed. Trying to figure out what was installed and get it reinstalled can be challenging.

While the source of the corruption is most likely accidental power loss and not the fault of HACS, it would be a feature if it was easier to recover from this event.

Looking at the corrupted hacs.repositories file. It was tracking 1,470 repos of which only 12 repos were installed. Data about the 12 installed repos changes less frequently than the list of available repos. If that data was stored separately, or at least there was a list of repos installed and the version details it would make the recovery process easier.

Reproduction steps

  1. Cause .storage/hacs.repositories to become corrupted, restart Home Assistant
  2. Observe there are no repos available in HACS after restart
  3. Find the hacs.repositories.corrupt.timestamp file in config/.storage
  4. search for the version_installed key to try to piece together the previous state and figure out what repos to reinstall
  5. Alternatively unpack the most recent backup that might not be corrupt and includes .storage/hacs.repositories in some other location. Shut down Home Assistant, copy the file back into .storage. Restart home assistant. ...

Debug logs

Feb 11 22:37:43 homeassistant homeassistant[443]: 2024-02-11 17:37:43.491 ERROR (SyncWorker_6) [homeassistant.util.json] Could not parse JSON content: /config/.storage/hacs.repositories
Feb 11 22:37:43 homeassistant homeassistant[443]: Traceback (most recent call last):
Feb 11 22:37:43 homeassistant homeassistant[443]:   File "/usr/src/homeassistant/homeassistant/util/json.py", line 77, in load_json
Feb 11 22:37:43 homeassistant homeassistant[443]:     return orjson.loads(fdesc.read())  # type: ignore[no-any-return]
Feb 11 22:37:43 homeassistant homeassistant[443]:            ^^^^^^^^^^^^^^^^^^^^^^^^^^
Feb 11 22:37:43 homeassistant homeassistant[443]: orjson.JSONDecodeError: unexpected character: line 5708 column 3 (char 188342)
Feb 11 22:37:43 homeassistant homeassistant[443]: 2024-02-11 17:37:43.983 ERROR (MainThread) [homeassistant.helpers.storage] Unrecoverable error decoding storage hacs.repositories at /config/.storage/hacs.repoitories; This may indicate an  unclean shutdown, invalid syntax from manual edits, or disk corruption; The corrupt file has been saved as /config/.storage/hacs.repositories.corrupt.2024-02-11T22:37:43.813658+00:00; It is recommended to restore from backup: unexpected character: line 5708 column 3 (char 188342)


### Diagnostics dump

_No response_
hacs-bot[bot] commented 7 months ago

Make sure you have read the issue guidelines and that you filled out the entire template.

If you have an issue identical to this, do not add comments like "same here", "i have this too", instead add a :+1: reaction to the issue description. Thanks! :+1:

ludeeus commented 7 months ago

It wouldd not matter where it was stored. Once your storage media starts to fail like that you should look at alternatives.