Skip to content
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

Issue with Payloads Detail Index out of Range #40

Closed
adam-olson opened this issue May 18, 2022 · 2 comments
Closed

Issue with Payloads Detail Index out of Range #40

adam-olson opened this issue May 18, 2022 · 2 comments

Comments

@adam-olson
Copy link

Looks like it doesn't like something in the payloads index.

2022-05-18 14:19:11 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 137, in _handle_refresh_interval await self._async_refresh(log_failures=True, scheduled=True) File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 270, in _async_refresh update_callback() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 533, in async_write_ha_state self._async_write_ha_state() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 571, in _async_write_ha_state state = self._stringify_state(available) File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 539, in _stringify_state if (state := self.state) is None: File "/config/custom_components/spacex/sensor.py", line 559, in state self._state = launch_data["payloads_detail"][0]["name"] IndexError: list index out of range

--
Adam

@jensihnow
Copy link

Same here, sometimes just flooding the log:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 137, in _handle_refresh_interval
    await self._async_refresh(log_failures=True, scheduled=True)
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 270, in _async_refresh
    update_callback()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 533, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 571, in _async_write_ha_state
    state = self._stringify_state(available)
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 539, in _stringify_state
    if (state := self.state) is None:
  File "/config/custom_components/spacex/sensor.py", line 559, in state
    self._state = launch_data["payloads_detail"][0]["name"]
IndexError: list index out of range

The value spacex_next_launch_payload (sensor.next_launch_payload) is unavailable. Looking at the API response (https://api.spacexdata.com/v4/launches/next) I see the payload very well undefined:

  "fairings": {
    "reused": null,
    "recovery_attempt": null,
    "recovered": null,
    "ships": []
  },
  "links": {
    "patch": {
      "small": null,
      "large": null
    },
    "reddit": {
      "campaign": null,
      "launch": null,
      "media": null,
      "recovery": null
    },
    "flickr": {
      "small": [],
      "original": []
    },
    "presskit": null,
    "webcast": null,
    "youtube_id": null,
    "article": null,
    "wikipedia": null
  },
  "static_fire_date_utc": null,
  "static_fire_date_unix": null,
  "net": false,
  "window": null,
  "rocket": "5e9d0d95eda69973a809d1ec",
  "success": null,
  "failures": [],
  "details": null,
  "crew": [],
  "ships": [],
  "capsules": [],
  "payloads": [],
  "launchpad": "5e9e4501f509094ba4566f84",
  "flight_number": 165,
  "name": "Transporter-5",
  "date_utc": "2022-05-25T18:27:00.000Z",
  "date_unix": 1653503220,
  "date_local": "2022-05-25T14:27:00-04:00",
  "date_precision": "hour",
  "upcoming": true,
  "cores": [
    {
      "core": "5f57c53d0622a6330279009f",
      "flight": 8,
      "gridfins": true,
      "legs": true,
      "reused": true,
      "landing_attempt": null,
      "landing_success": null,
      "landing_type": null,
      "landpad": null
    }
  ],
  "auto_update": true,
  "tbd": false,
  "launch_library_id": "949421ac-3802-499b-b383-d8274de7e147",
  "id": "6243ae24af52800c6e919258"
}

I guess this needs to be caught in code as SpaceX is not providing this data for each launch. I wonder if there is more values which might be missing and the code path should handle this accordingly.

@adam-olson
Copy link
Author

Looks like it is happening again.

2022-06-20 14:50:50 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 137, in _handle_refresh_interval await self._async_refresh(log_failures=True, scheduled=True) File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 270, in _async_refresh update_callback() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 533, in async_write_ha_state self._async_write_ha_state() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 571, in _async_write_ha_state state = self._stringify_state(available) File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 539, in _stringify_state if (state := self.state) is None: File "/config/custom_components/spacex/sensor.py", line 559, in state self._state = launch_data["payloads_detail"][0]["name"] IndexError: list index out of range

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants