From 50774454e1424c719b082e8b704296f47a7e0f7d Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Mon, 19 Sep 2022 07:26:53 +0300 Subject: Refactor: raise appropriate error If a file/directory does not exist, raise the builtin `FileNotFoundError` rather than the generic `Exception`. --- wqflask/utility/tools.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'wqflask/utility') diff --git a/wqflask/utility/tools.py b/wqflask/utility/tools.py index 19bf686b..fe059015 100644 --- a/wqflask/utility/tools.py +++ b/wqflask/utility/tools.py @@ -152,10 +152,10 @@ def assert_bin(fn): return fn -def assert_dir(dir): - if not valid_path(dir): - raise Exception("ERROR: can not find directory " + dir) - return dir +def assert_dir(the_dir): + if not valid_path(the_dir): + raise FileNotFoundError(f"ERROR: can not find directory '{the_dir}'") + return the_dir def assert_writable_dir(dir): @@ -172,7 +172,7 @@ def assert_writable_dir(dir): def assert_file(fn): if not valid_file(fn): - raise Exception('Unable to find file ' + fn) + raise FileNotFoundError(f"Unable to find file '{fn}'") return fn -- cgit v1.2.3