Error handling with the fitdecode library to read fit files in python

I would love to work with my workout recordings (runs, bike rides etc.) in python. To do so, I first need to read the recordings (fit file) into python.

I am using the fitdecode library which works fine. Now I am trying to specify the parameter that tells the reader how to treat errors within the file.

The code still looks like this which is pretty much the example given with the documentation.

import fitdecode
with fitdecode.FitReader('464491592495955971.fit') as fit:
    for frame in fit:
        # The yielded frame object is of one of the following types:
        # * fitdecode.FitHeader (FIT_FRAME_HEADER)
        # * fitdecode.FitDefinitionMessage (FIT_FRAME_DEFINITION)
        # * fitdecode.FitDataMessage (FIT_FRAME_DATA)
        # * fitdecode.FitCRC (FIT_FRAME_CRC)

        if frame.frame_type == fitdecode.FIT_FRAME_DATA:
            # Here, frame is a FitDataMessage object.
            # A FitDataMessage object contains decoded values that
            # are directly usable in your script logic.
            print(frame.name)

I am adding the error handling parameter to the reader as explained here.

The following specifications did not work:

fitdecode.FitReader('464491592495955971.fit', error_handling=0)
fitdecode.FitReader('464491592495955971.fit', error_handling='IGNORE')
fitdecode.FitReader('464491592495955971.fit', error_handling=IGNORE)

They all return an assertion error like this:

File ~/Documents/Python/Environment/lib/python3.13/site-packages/fitdecode/reader.py:164, in FitReader.__init__(self, fileish, processor, check_crc, error_handling, keep_raw_chunks, data_bag)
    161     check_crc = CrcCheck.DISABLED
    163 assert isinstance(check_crc, CrcCheck)
--> 164 assert isinstance(error_handling, ErrorHandling)
    166 # modifiable options (public)
    167 self.check_crc = check_crc

Can anybody help me with the correct error handling?

Thanks so much.

You’re on the right track — the issue lies in how you’re passing the error_handling parameter to fitdecode.FitReader.

The error_handling argument expects an enum member from fitdecode.ErrorHandling, not a string or integer.


Correct Usage

You need to import ErrorHandling from fitdecode like this:

import fitdecode
from fitdecode import ErrorHandling

with fitdecode.FitReader(
    '464491592495955971.fit',
    error_handling=ErrorHandling.IGNORE  #  this is the correct way
) as fit:
    for frame in fit:
        if frame.frame_type == fitdecode.FIT_FRAME_DATA:
            print(frame.name)

Available ErrorHandling Modes

You can choose from:

  • ErrorHandling.STRICT — raise exceptions (default).
  • ErrorHandling.WARN — log warnings instead of raising.
  • ErrorHandling.IGNORE — silently skip invalid data.