Skip to content

Commit

Permalink
FITIO handling for out-of-range field values
Browse files Browse the repository at this point in the history
  • Loading branch information
cpfair committed Nov 30, 2013
1 parent 2e0d6b4 commit 8af67b9
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion tapiriik/services/fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,13 @@ def GenerateMessage(self, name, **kwargs):
else:
if field_type.PackFormat in ["B","b", "H", "h", "I", "i"]:
sanitized_value = round(sanitized_value)
result = struct.pack("<" + field_type.PackFormat, sanitized_value)
try:
result = struct.pack("<" + field_type.PackFormat, sanitized_value)
except struct.error as e: # I guess more specific exception types were too much to ask for.
if "<=" in str(e):
result = struct.pack("<" + field_type.PackFormat, field_type.InvalidValue)
else:
raise
except Exception as e:
raise Exception("Failed packing %s=%s - %s" % (field_name, kwargs[field_name], e))
packResult.append(result)
Expand Down

0 comments on commit 8af67b9

Please sign in to comment.