Poeschl / Hassio-Addons

The repository for my Home Assistant Supervisor Add-ons.
Apache License 2.0
308 stars 92 forks source link

[git-exporter] jq: error (at <stdin>:1): Cannot iterate over null (null) #325

Closed bjeanes closed 2 years ago

bjeanes commented 2 years ago

Which addon? git-exporter

Describe the bug It no longer runs due to failing to get add-ons:

Screen Shot 2022-07-19 at 5 06 01 pm

To Reproduce

Unclear, it may be a HA version thing. I have fiddled around a bit and deduced that based on https://github.com/Poeschl/Hassio-Addons/blob/0e0cd58135754f7fdddbb29431b07d766af6f63e/git-exporter/root/run.sh#L142 ... the /addons call used to have a top-level "repositories" key.

On HA 2022.7, this appears not to be the case (not sure when it broke).

[core-ssh ~]$ bashio::api.supervisor GET "/addons" false | jq -C 'keys'
[
  "addons"
]

Based on https://developers.home-assistant.io/docs/api/supervisor/endpoints/, it seems like it should be using /store/repositories instead:

[core-ssh ~]$ bashio::api.supervisor GET "/store/repositories" false | jq -C '.[]|keys[]'|sort -u
"maintainer"
"name"
"slug"
"source"
"url"

System

Poeschl commented 2 years ago

Waiting for an answer on https://github.com/hassio-addons/bashio/issues/111 for this.

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Poeschl commented 2 years ago

Will be fixed with the next merge from dev. Sch bot

bjeanes commented 1 year ago

Hmm, not sure if there have been other changes besides this but today was the first time I ran the exporter since it stopped working, and I was surprised to see it deleted all addon configuration:

[main 715aeff] Home Assistant Git Exporter
 38 files changed, 1046 insertions(+), 403 deletions(-)
 delete mode 100644 addons/243ffc37_git-exporter.yaml
 delete mode 100644 addons/243ffc37_rsync.yaml
 delete mode 100644 addons/243ffc37_syncthing.yaml
 delete mode 100644 addons/45df7312_zigbee2mqtt.yaml
 delete mode 100644 addons/77b2833f_timescaledb.yaml
 delete mode 100644 addons/9c51689a_pgweb.yaml
 delete mode 100644 addons/a0d7b954_esphome.yaml
 delete mode 100644 addons/a0d7b954_nodered.yaml
 delete mode 100644 addons/a0d7b954_zerotier.yaml
 delete mode 100644 addons/cebe7a76_hassio_google_drive_backup.yaml
 delete mode 100644 addons/core_configurator.yaml
 delete mode 100644 addons/core_mosquitto.yaml
 delete mode 100644 addons/core_samba.yaml
 delete mode 100644 addons/core_ssh.yaml

@Poeschl was that intentional?

Poeschl commented 1 year ago

The retrieval of the addon config changed. That shouldn't delete all configs. Are they added again?

bjeanes commented 1 year ago

They are not. They just don't export anymore.

The only thing in the addons dir is the repositories.yaml - https://git.bjeanes.com/bo/ha-config/src/branch/main/addons

Poeschl commented 1 year ago

Do you find any log output from this line bashio::log.info "Get ${addon} configs" on your last run?

If not the addons api have changed also.

bjeanes commented 1 year ago

That line doesn't even show up, even though I have addons: true in configuration:

[14:25:01] INFO: Start git export
[14:25:01] INFO: Pull latest
From https://git.bjeanes.com/bo/ha-config
   715aeff..8d3df54  main       -> origin/main
HEAD is now at 8d3df54 Ignore solcast forecast file
[14:25:02] INFO: Get Home Assistant config
[14:25:02] INFO: Get Lovelace config yaml
[14:25:03] INFO: Get ESPHome configs
[14:25:04] INFO: Get addon repositories
[14:25:04] INFO: Get Node-RED flows
[14:25:05] INFO: Add secrets pattern
[14:25:05] INFO: Add secrets from secrets.yaml
[14:25:05] INFO: Prohibited patterns:
password:\s?[\'"]?\w+[\'"]?\n?
token:\s?[\'"]?\w+[\'"]?\n?
client_id:\s?[\'"]?\w+[\'"]?\n?
api_key:\s?[\'"]?\w+[\'"]?\n?
chat_id:\s?[\'"]?\w+[\'"]?\n?
allowed_chat_ids:\s?[\'"]?\w+[\'"]?\n?
latitude:\s?[\'"]?\w+[\'"]?\n?
longitude:\s?[\'"]?\w+[\'"]?\n?
credential_secret:\s?[\'"]?\w+[\'"]?\n?
[14:25:05] INFO: Checking for secrets
[14:25:06] INFO: Commit changes and push to remote
[main 8f1ebd0] Home Assistant Git Exporter
 2 files changed, 4 insertions(+), 3 deletions(-)
remote: . Processing 1 references        
remote: Processed 1 references in total        
To https://git.bjeanes.com/bo/ha-config.git
   8d3df54..8f1ebd0  main -> main
[14:25:15] INFO: Exporter finished
Poeschl commented 1 year ago

Seems that we have a new issue then 😅

The return of the addons does not return any installed addons or has changed. 😐

bjeanes commented 1 year ago

I tested this in Terminal add-on.

I have this helper to experiment with bashio commands interactively:

function bashio() {
  # load bashio, then unset flags which cause it to exit on any failure
  bash --init-file <(echo "source /usr/lib/bashio/bashio.sh; set +o errexit; set +o errtrace; set +o nounset; set +o pipefail")
}

Here:

~ $ bashio::addons.installed # no output
~ $ bashio::addons | jq '.addons | length'
23
~ $ bashio::addons | jq '.addons[0]'
{
  "name": "Samba share",
  "slug": "core_samba",
  "description": "Expose Home Assistant folders with SMB/CIFS",
  "advanced": false,
  "stage": "stable",
  "version": "10.0.0",
  "version_latest": "10.0.0",
  "update_available": false,
  "available": true,
  "detached": false,
  "homeassistant": null,
  "state": "started",
  "repository": "core",
  "build": false,
  "url": "https://github.com/home-assistant/hassio-addons/tree/master/samba",
  "icon": true,
  "logo": true
}
~ $ bashio::addons.installed core_samba
true

It looks like you are already iterating over the addons to check if installed https://github.com/Poeschl/Hassio-Addons/blob/f67bb090029561153d8b40a541d9f6fb3111b5a2/git-exporter/root/run.sh#L133-L134

So in principle, just removing .installed here should fix the issue https://github.com/Poeschl/Hassio-Addons/blob/f67bb090029561153d8b40a541d9f6fb3111b5a2/git-exporter/root/run.sh#L131

WDYT?