Skip to content

Commit 81f6611

Browse files
committed
handle IO exception
1 parent 5330332 commit 81f6611

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

lib/bald/__init__.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import contextlib
22
import copy
3+
import os
34
import re
45
import time
56

@@ -641,12 +642,17 @@ def load(afilepath):
641642
elif afilepath.endswith('.nc'):
642643
loader = netCDF4.Dataset
643644
else:
644-
raise ValueError('filepath suffix not supported')
645+
raise ValueError('filepath suffix not supported: {}'.format(afilepath))
646+
if not os.path.exists(afilepath):
647+
raise IOError('{} not found'.format(afilepath))
645648
try:
646649
f = loader(afilepath, "r")
647650
yield f
648651
finally:
649-
f.close()
652+
try:
653+
f.close()
654+
except NameError:
655+
pass
650656

651657
def load_netcdf(afilepath, baseuri=None, alias_dict=None, cache=None):
652658
"""

0 commit comments

Comments
 (0)