Skip to content

Commit

Permalink
Fix for IndexError in ggtracker#149
Browse files Browse the repository at this point in the history
Fixes ggtracker#149…. Please review for the side effects of setting:
`self.region = self.map_hash = self.map_file = ""`
  • Loading branch information
cclauss authored Aug 12, 2021
1 parent af3628e commit af8c90d
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions sc2reader/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,16 @@ def load_details(self):
return

self.map_name = details["map_name"]
self.region = details["cache_handles"][0].server.lower()
self.map_hash = details["cache_handles"][-1].hash
self.map_file = details["cache_handles"][-1]
cache_handles = details["cache_handles"]
if cache_handles: # Fix for issue ggtracker/sc2reader#149
self.region = cache_handles[0].server.lower()
self.map_hash = cache_handles[-1].hash
self.map_file = cache_handles[-1]
else:
self.region = self.map_hash = self.map_file = ""
self.logger.warn(
"Details {map_name} has cache_handles={cache_handles}".format(**details)
)

# Expand this special case mapping
if self.region == "sg":
Expand Down

2 comments on commit af8c90d

@brean
Copy link

@brean brean commented on af8c90d Sep 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.expansion might be an empty string on AI-replay games:

>>> replay = sc2reader.load_replay('replays/2022-06-26_12-24-24.sc2replay')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/user/.local/lib/python3.10/site-packages/sc2reader/factories/sc2factory.py", line 88, in load_replay
    return self.load(Replay, source, options, **new_options)
  File "/home/user/.local/lib/python3.10/site-packages/sc2reader/factories/sc2factory.py", line 166, in load
    return self._load(cls, resource, filename=filename, options=options)
  File "/home/user/.local/lib/python3.10/site-packages/sc2reader/factories/sc2factory.py", line 175, in _load
    obj = cls(resource, filename=filename, factory=self, **options)
  File "/home/user/.local/lib/python3.10/site-packages/sc2reader/resources.py", line 302, in __init__
    self.load_all_details()
  File "/home/user/.local/lib/python3.10/site-packages/sc2reader/resources.py", line 452, in load_all_details
    self.load_details()
  File "/home/user/.local/lib/python3.10/site-packages/sc2reader/resources.py", line 442, in load_details
    // GAME_SPEED_FACTOR[self.expansion].get(self.speed, 1.0)
KeyError: ''

Maybe we should default to 'LotV'?

@craigdods
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.expansion might be an empty string on AI-replay games:

>>> replay = sc2reader.load_replay('replays/2022-06-26_12-24-24.sc2replay')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/user/.local/lib/python3.10/site-packages/sc2reader/factories/sc2factory.py", line 88, in load_replay
    return self.load(Replay, source, options, **new_options)
  File "/home/user/.local/lib/python3.10/site-packages/sc2reader/factories/sc2factory.py", line 166, in load
    return self._load(cls, resource, filename=filename, options=options)
  File "/home/user/.local/lib/python3.10/site-packages/sc2reader/factories/sc2factory.py", line 175, in _load
    obj = cls(resource, filename=filename, factory=self, **options)
  File "/home/user/.local/lib/python3.10/site-packages/sc2reader/resources.py", line 302, in __init__
    self.load_all_details()
  File "/home/user/.local/lib/python3.10/site-packages/sc2reader/resources.py", line 452, in load_all_details
    self.load_details()
  File "/home/user/.local/lib/python3.10/site-packages/sc2reader/resources.py", line 442, in load_details
    // GAME_SPEED_FACTOR[self.expansion].get(self.speed, 1.0)
KeyError: ''

Maybe we should default to 'LotV'?

Tried fixing this with the two commits referenced here - thoughts?

ggtracker#149

Please sign in to comment.