Skip to content

Commit 49d6a09

Browse files
committed
Adds type and code information to ReadErrors.
Also removes the now unused ParseError exception.
1 parent 7d2f1a3 commit 49d6a09

File tree

2 files changed

+3
-21
lines changed

2 files changed

+3
-21
lines changed

sc2reader/exceptions.py

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class MutipleMatchingFilesError(SC2ReaderError):
88
pass
99

1010
class ReadError(SC2ReaderError):
11-
def __init__(self, msg, replay=None, game_events=[], buffer=None, location=None):
11+
def __init__(self, msg, type, code, location, replay=None, game_events=[], buffer=None):
1212
self.__dict__.update(locals())
1313
super(ReadError, self).__init__(msg)
1414

@@ -17,19 +17,3 @@ class ProcessError(SC2ReaderError):
1717

1818
class FileError(SC2ReaderError):
1919
pass
20-
21-
22-
class ParseError(Exception):
23-
def __init__(self, message, replay, event, bytes):
24-
self.message = message
25-
self.replay = replay
26-
self.event = event
27-
self.bytes = bytes
28-
29-
def __str__(self):
30-
return """ParseError %s
31-
%s - %s
32-
%s""" % (self.message, self.event.type, self.event.code, self.bytes)
33-
34-
def __repr__(self):
35-
return str(self)

sc2reader/readers.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,15 +231,13 @@ def __call__(self, buffer, replay):
231231
# If the type is not a key in the PARSERS lookup table we
232232
# probably incorrectly parsed the previous event
233233
# TODO: Raise an error instead an store the previous event
234-
msg = "Unknown event type: {0:X} - {1:X} at {2:X}".format(type, code, start)
235-
raise exceptions.ReadError(msg, replay, game_events, buffer, start)
234+
raise exceptions.ReadError("Unknown event type", type, code, start, replay, game_events, buffer)
236235

237236
except TypeError:
238237
# For some reason, the type handler that we delegated to didn't
239238
# recognize the event code that we extracated.
240239
# TODO: Do something meaningful here
241-
msg = "Unknown event code: {0:X} - {1:X} at {2:X}".format(type, code, start)
242-
raise exceptions.ReadError(msg, replay, game_events, buffer, start)
240+
raise exceptions.ReadError("Unknown event code", type, code, start, replay, game_events, buffer)
243241

244242
except exceptions.ReadError as e:
245243
raise exceptions.ReadError(e.msg, replay, game_events, buffer, start)

0 commit comments

Comments
 (0)