Skip to content

Commit 9e111dd

Browse files
committed
RF: Add testing for file existence up front.
Raises an informative error when the file doesn't exist.
1 parent 7562b59 commit 9e111dd

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

nibabel/loadsave.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
# module imports
1010
""" Utilities to load and save image objects """
1111

12+
import os.path as op
1213
import numpy as np
1314
import warnings
1415

@@ -34,6 +35,8 @@ def load(filename, **kwargs):
3435
img : ``SpatialImage``
3536
Image of guessed type
3637
'''
38+
if not op.exists(filename):
39+
raise FileNotFoundError("No such file: '%s'" % filename)
3740
sniff = None
3841
for image_klass in all_image_classes:
3942
is_valid, sniff = image_klass.path_maybe_image(filename, sniff)

0 commit comments

Comments
 (0)