summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMac Mollison <mollison@cs.unc.edu>2010-03-26 12:25:05 -0400
committerMac Mollison <mollison@cs.unc.edu>2010-03-26 12:25:05 -0400
commit1b7984c779cc47c69e93a77180bd63361b7cde6b (patch)
treefe839b38acf08ff883d170ab0a21e943e6de9fed
parentf72934ce186fa4cd9cf908316706ed733949f192 (diff)
Print warning on bad records rather than halting
-rw-r--r--unit_trace/trace_reader.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/unit_trace/trace_reader.py b/unit_trace/trace_reader.py
index e1d2095..3cbce17 100644
--- a/unit_trace/trace_reader.py
+++ b/unit_trace/trace_reader.py
@@ -125,15 +125,21 @@ def _get_file_iter(file):
125 type_num = struct.unpack_from('b',data)[0] 125 type_num = struct.unpack_from('b',data)[0]
126 except struct.error: 126 except struct.error:
127 break #We read to the end of the file 127 break #We read to the end of the file
128 type = _get_type(type_num) 128 try:
129 type = _get_type(type_num)
130 except:
131 sys.stderr.write("Skipping record with invalid type num: %d\n" %
132 (type_num))
133 continue
129 try: 134 try:
130 values = struct.unpack_from(StHeader.format + 135 values = struct.unpack_from(StHeader.format +
131 type.format,data) 136 type.format,data)
132 record_dict = dict(zip(type.keys,values)) 137 record_dict = dict(zip(type.keys,values))
133 except struct.error: 138 except struct.error:
134 f.close() 139 f.close()
135 print "Invalid record detected, stopping." 140 sys.stderr.write("Skipping record that does not match proper" +
136 exit() 141 " struct formatting\n")
142 continue
137 143
138 # Convert the record_dict into an object 144 # Convert the record_dict into an object
139 record = _dict2obj(record_dict) 145 record = _dict2obj(record_dict)