Skip to content

Commit 13e3749

Browse files
committed
Catch mpyq exceptions and wrap in MPQError.
This could use improvement, but atleast lets us know by error type where the error actually occured. This should help substantially with debugging. Hopefully arkx can be convinced to wrap up his exceptions so we can avoid this little bit of ugly in the future.
1 parent 1d177fd commit 13e3749

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

sc2reader/__init__.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,27 @@ def read(self, location, **user_options):
100100
# add messages promoting their sites without updating the header
101101
# correctly. The listfile option(hack) lets us bypass this issue
102102
# by specifying the files we want instead of generating a list.
103-
archive = mpyq.MPQArchive(location, listfile=False)
103+
#
104+
# In order to wrap mpyq exceptions we have to do this try hack.
105+
try:
106+
archive = mpyq.MPQArchive(location, listfile=False)
107+
except KeyboardInterrupt: raise
108+
except:
109+
raise exceptions.MPQError("Unable to construct the MPQArchive")
104110

105111
# These files are configured for either full or partial parsing
106112
for file in options.files:
107113

114+
# To wrap mpyq exceptions we have to do this try hack.
115+
try:
116+
filedata = archive.read_file(file)
117+
except KeyboardInterrupt: raise
118+
except:
119+
raise exceptions.MPQError("Unable to extract file: {0}".format(file))
120+
108121
# For each file, we build a smart buffer object from the
109122
# utf-8 encoded bitstream that mpyq extracts.
110-
buffer = utils.ReplayBuffer(archive.read_file(file))
123+
buffer = utils.ReplayBuffer(filedata)
111124

112125
# Each version of Starcraft slightly modifies some portions
113126
# of the format for some files. To work with this, the

sc2reader/exceptions.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
class SC2ReaderError(Exception):
22
pass
33

4+
class MPQError(SC2ReaderError):
5+
pass
6+
47
class NoMatchingFilesError(SC2ReaderError):
58
pass
69

0 commit comments

Comments
 (0)