Skip to content

Commit

Permalink
Handle decoding errors when parsing the character name
Browse files Browse the repository at this point in the history
Wrap the UnicodeDecodeError exception and throw D2SFileParseError instead.
Fixes #1
  • Loading branch information
artcom-net committed Oct 9, 2020
1 parent 898e16d commit e2cc4ea
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion d2lib/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,13 @@ def _read_header(self):
)

self.active_weapon_slot = int_from_lbytes(self._reader.read(4))
self.char_name = self._reader.read(16).rstrip(b'\x00').decode('ASCII')

try:
self.char_name = (
self._reader.read(16).rstrip(b'\x00').decode('ASCII')
)
except UnicodeDecodeError as error:
raise D2SFileParseError(f'Error parsing character name: {error}')

self.char_status = CharacterStatus(
int_from_lbytes(self._reader.read(1))
Expand Down

0 comments on commit e2cc4ea

Please sign in to comment.