Skip to content

Commit

Permalink
implement directory not found exception
Browse files Browse the repository at this point in the history
  • Loading branch information
amoh-godwin committed Feb 20, 2021
1 parent dc62880 commit 04440a7
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion recursive_size/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,18 @@ def get_size(folder_name):
try:
conts = os.listdir(folder_name)

except:
except NotADirectoryError:
try:
return os.stat(folder_name).st_size

except Exception as exc:
# Send early error back to user
raise RuntimeError(f'Unable to read {folder_name}') from exc

except Exception as exc:
# Send early error back to user
raise RuntimeError(f'Unable to read {folder_name}') from exc

for x in conts:
y = os.path.join(folder_name, x)
total += looper(y)
Expand Down

0 comments on commit 04440a7

Please sign in to comment.