Skip to content

Commit 3c4ef60

Browse files
committed
Merge pull request #65 from bridadan/catch-oserror
Catch OSError when listing files in mount point
2 parents 85277ef + 05ef921 commit 3c4ef60

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

mbed_lstools/lstools_base.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -487,15 +487,20 @@ def get_mbed_htm(self, mount_point):
487487
def get_mbed_htm_lines(self, mount_point):
488488
result = []
489489
if mount_point:
490-
for mount_point_file in [f for f in listdir(mount_point) if isfile(join(mount_point, f))]:
491-
if mount_point_file.lower() == self.MBED_HTM_NAME:
492-
mbed_htm_path = os.path.join(mount_point, mount_point_file)
493-
try:
494-
with open(mbed_htm_path, 'r') as f:
495-
result = f.readlines()
496-
except IOError:
497-
if self.DEBUG_FLAG:
498-
self.debug(self.get_mbed_htm_target_id.__name__, ('Failed to open file', mbed_htm_path))
490+
try:
491+
for mount_point_file in [f for f in listdir(mount_point) if isfile(join(mount_point, f))]:
492+
if mount_point_file.lower() == self.MBED_HTM_NAME:
493+
mbed_htm_path = os.path.join(mount_point, mount_point_file)
494+
try:
495+
with open(mbed_htm_path, 'r') as f:
496+
result = f.readlines()
497+
except IOError:
498+
if self.DEBUG_FLAG:
499+
self.debug(self.get_mbed_htm_target_id.__name__, ('Failed to open file', mbed_htm_path))
500+
except OSError:
501+
if self.DEBUG_FLAG:
502+
self.debug(self.get_mbed_htm_target_id.__name__, ('Failed to list mount point', mount_point))
503+
499504
return result
500505

501506
def get_details_txt(self, mount_point):

0 commit comments

Comments
 (0)