diff --git a/nipype/utils/filemanip.py b/nipype/utils/filemanip.py index 4f04b73a1e..6e6fb83623 100644 --- a/nipype/utils/filemanip.py +++ b/nipype/utils/filemanip.py @@ -682,6 +682,7 @@ def loadpkl(infile): pklopen = gzip.open if infile.suffix == '.pklz' else open pkl_metadata = None + unpkl = None with indirectory(infile.parent): pkl_file = pklopen(infile.name, 'rb') @@ -711,11 +712,14 @@ def loadpkl(infile): No metadata was found in the pkl file. Make sure you are currently using \ the same Nipype version from the generated pkl.""") raise e - else: - return unpkl finally: pkl_file.close() + if unpkl is None: + raise ValueError('Loading %s resulted in None.' % infile) + + return unpkl + def crash2txt(filename, record): """ Write out plain text crash file """