Skip to content

More helpful error messages when uncompressed file is passed with compressed extension #966

@effigies

Description

@effigies

We have a pretty one-size-fits-all error when we can't determine the file type:

$ head -c 1000 /dev/zero > test.nii.gz
$ python -c "import nibabel as nb; nb.load('test.nii.gz')"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File ".../nibabel/nibabel/loadsave.py", line 55, in load
    raise ImageFileError(f'Cannot work out file type of "{filename}"')
nibabel.filebasedimages.ImageFileError: Cannot work out file type of "test.nii.gz"

A relatively common situation is an uncompressed NIfTI that got renamed x.nii.gz. It's fairly straightforward to identify data that isn't gzip or bzip2 by magic number, so we could help people out with a message like File "test.nii.gz" is not a gzip file.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions