Skip to content

Add error handling to _read_header #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion fitdecode/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,17 @@ def _update_state():
assert self._body_bytes_left == 0

self._reset_per_fit_state()
self._read_header()

try:
self._read_header()
except FitHeaderError as e:
if self.error_handling is ErrorHandling.RAISE:
raise
elif self.error_handling is ErrorHandling.WARN:
warnings.warn(str(e))
# Skip the bad header and continue to the next one
_update_state()
continue
if self._header is None:
break

Expand Down