MLB-LED-Scoreboard / mlb-led-scoreboard

An LED scoreboard for Major League Baseball :baseball:
GNU General Public License v3.0
590 stars 105 forks source link

Ensure preferred game index is bounded by game list length #411

Closed ty-porter closed 1 year ago

ty-porter commented 1 year ago

Closes #410 & #362 which was previously closed earlier this season when we rolled to v5

We guard against IndexError in other places by rolling over to 0 on overflow (namely the call to __next_game_index). For some reason this function just never had the same handling for that issue in the preferred games index

My hunch is that the call to refresh the games list returns a list that's smaller than current index. Normally this isn't a problem, but when current index >= new list size AND when preferred team isn't live, you'd go out of bounds. This will be hard to test unfortunately as it is very dependent on data in the MLB API. To me, this type of guard feels like a good idea even if it doesn't fully address this issue.

Stack traces for the two issues are almost identical. Latest version (5.1.4) changes the next_game call slightly but would not affect this issue


Copying the stack trace here for visibility:

ERROR (12:42:26): Untrapped error in main!
Traceback (most recent call last):
  File "/home/pi/mlb-led-scoreboard/main.py", line 144, in <module>
    main(matrix, config)
  File "/home/pi/mlb-led-scoreboard/main.py", line 78, in main
    __refresh_games(render, data)
  File "/home/pi/mlb-led-scoreboard/main.py", line 115, in __refresh_games
    data.advance_to_next_game()
  File "/home/pi/mlb-led-scoreboard/data/__init__.py", line 75, in advance_to_next_game
    game = self.schedule.next_game()
  File "/home/pi/mlb-led-scoreboard/data/schedule.py", line 106, in next_game
    preferred_game = Game.from_ID(self._games[game_index]["game_id"], self.date)
IndexError: list index out of range
WardBrian commented 1 year ago

Couldn’t this still fail if the refresh takes the number of games down to 0?