@@ -108,10 +108,10 @@ def to_line(self) -> bytes:
108
108
109
109
110
110
class Hy3Record :
111
- record_type : str
112
- fields : list [Field ]
113
- data : dict [str , Any ]
114
- raw : bytes
111
+ record_type : str = ""
112
+ fields : list [Field ] = []
113
+ data : dict [str , Any ] = {}
114
+ raw : bytes = b""
115
115
children : list [Type [Hy3Record | Hy3RecordGroup ]] = []
116
116
117
117
def __init__ (self , raw : bytes = b"" , / , ** kwargs ):
@@ -204,14 +204,16 @@ def parse_record(cls, line: bytes):
204
204
return cls (line )
205
205
given_checksum = line [- 2 :]
206
206
if cls .calculate_checksum (line [:- 2 ]) != given_checksum :
207
- print (line , type (line ))
208
207
raise Exception ("Bad checksum" )
209
208
params = {}
210
209
index = 2
211
210
for field in cls .fields :
212
211
data = line [index :index + field .length ]
213
212
index += field .length
214
- params [field .name ] = field .type (data .decode ("utf-8" , errors = "replace" ).strip ())
213
+ try :
214
+ params [field .name ] = field .type (data .decode ("utf-8" , errors = "replace" ).strip ())
215
+ except Exception as e :
216
+ raise Exception (f"Failed to parse field { field .name } as { field .type .__name__ } : { e } " ) from e
215
217
return cls (line , ** params )
216
218
217
219
@staticmethod
@@ -297,6 +299,7 @@ class Hy3C3Record(Hy3Record):
297
299
fields = []
298
300
# here for completeness, contains contact info
299
301
302
+ # one of the files i have has a C8 record
300
303
301
304
# Swimmer data
302
305
class Hy3D1Record (Hy3Record ):
0 commit comments