Catch error when done reading files (contrib/linearize-data.py)

Fixes #4893