diff pytouhou/formats/score.py @ 377:70e2ed71b09c

Add meaningful exceptions in format parsing.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Wed, 29 Aug 2012 18:34:28 +0200
parents 5492472963b0
children d1f0bb0b7a17
line wrap: on
line diff
--- a/pytouhou/formats/score.py
+++ b/pytouhou/formats/score.py
@@ -17,6 +17,8 @@ from struct import pack, unpack, Struct
 from collections import namedtuple
 from io import BytesIO
 
+from pytouhou.formats import ChecksumError
+
 
 class TH6Score(object):
     entry_types = {
@@ -78,8 +80,9 @@ class TH6Score(object):
         # Verify checksum
         if verify:
             #TODO: is there more to it?
-            if checksum != sum(ord(c) for c in file.read()) & 0xFFFF:
-                raise Exception
+            real_sum = sum(ord(c) for c in file.read()) & 0xFFFF
+            if checksum != real_sum:
+                raise ChecksumError(checksum, real_sum)
             file.seek(4)
 
         # Read second-part header