Skip to content

Commit

Permalink
raise FileNotFoundError in several contexts (#416)
Browse files Browse the repository at this point in the history
  • Loading branch information
njzjz authored Nov 20, 2023
1 parent 038ced7 commit 3052136
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 17 deletions.
14 changes: 8 additions & 6 deletions dpdispatcher/contexts/hdfs_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def upload(self, submission, dereference=True):
for ff in task.forward_files:
abs_file_list = glob(os.path.join(local_job, ff))
if not abs_file_list:
raise RuntimeError(
raise FileNotFoundError(
"cannot find upload file " + os.path.join(local_job, ff)
)
rel_file_list = [
Expand All @@ -100,7 +100,7 @@ def upload(self, submission, dereference=True):
for fc in submission.forward_common_files:
abs_file_list = glob(os.path.join(local_job, fc))
if not abs_file_list:
raise RuntimeError(
raise FileNotFoundError(
"cannot find upload file " + os.path.join(local_job, fc)
)
rel_file_list = [
Expand Down Expand Up @@ -170,9 +170,11 @@ def download(
) as fp:
pass
else:
raise RuntimeError("do not find download file " + rfile)
raise FileNotFoundError(
"do not find download file " + rfile
)
else:
raise RuntimeError("do not find download file " + rfile)
raise FileNotFoundError("do not find download file " + rfile)
else:
if os.path.exists(lfile):
dlog.info(f"find existing {lfile}, replacing by {rfile}")
Expand Down Expand Up @@ -203,9 +205,9 @@ def download(
) as fp:
pass
else:
raise RuntimeError("do not find download file " + rfile)
raise FileNotFoundError("do not find download file " + rfile)
else:
raise RuntimeError("do not find download file " + rfile)
raise FileNotFoundError("do not find download file " + rfile)
else:
if os.path.exists(lfile):
dlog.info(f"find existing {lfile}, replacing by {rfile}")
Expand Down
18 changes: 10 additions & 8 deletions dpdispatcher/contexts/local_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def upload(self, submission):
for kk in ii.forward_files:
abs_file_list = glob(os.path.join(local_job, kk))
if not abs_file_list:
raise RuntimeError(
raise FileNotFoundError(
"cannot find upload file " + os.path.join(local_job, kk)
)
rel_file_list = [
Expand All @@ -104,7 +104,7 @@ def upload(self, submission):

for jj in file_list:
if not os.path.exists(os.path.join(local_job, jj)):
raise RuntimeError(
raise FileNotFoundError(
"cannot find upload file " + os.path.join(local_job, jj)
)
if os.path.exists(os.path.join(remote_job, jj)):
Expand All @@ -119,7 +119,7 @@ def upload(self, submission):
for kk in submission.forward_common_files:
abs_file_list = glob(os.path.join(local_job, kk))
if not abs_file_list:
raise RuntimeError(
raise FileNotFoundError(
"cannot find upload file " + os.path.join(local_job, kk)
)
rel_file_list = [
Expand All @@ -129,7 +129,7 @@ def upload(self, submission):

for jj in file_list:
if not os.path.exists(os.path.join(local_job, jj)):
raise RuntimeError(
raise FileNotFoundError(
"cannot find upload file " + os.path.join(local_job, jj)
)
if os.path.exists(os.path.join(remote_job, jj)):
Expand Down Expand Up @@ -160,7 +160,7 @@ def download(
else:
pass
else:
raise RuntimeError(
raise FileNotFoundError(
"cannot find download file " + os.path.join(remote_job, kk)
)
rel_flist = [
Expand Down Expand Up @@ -188,7 +188,9 @@ def download(
else:
pass
else:
raise RuntimeError("do not find download file " + rfile)
raise FileNotFoundError(
"do not find download file " + rfile
)
elif (not os.path.exists(rfile)) and (os.path.exists(lfile)):
# already downloaded
pass
Expand Down Expand Up @@ -229,7 +231,7 @@ def download(
else:
pass
else:
raise RuntimeError(
raise FileNotFoundError(
"cannot find download file " + os.path.join(remote_job, kk)
)
rel_flist = [os.path.relpath(ii, start=remote_job) for ii in abs_flist_r]
Expand All @@ -255,7 +257,7 @@ def download(
else:
pass
else:
raise RuntimeError("do not find download file " + rfile)
raise FileNotFoundError("do not find download file " + rfile)
elif (not os.path.exists(rfile)) and (os.path.exists(lfile)):
# already downloaded
pass
Expand Down
2 changes: 1 addition & 1 deletion dpdispatcher/contexts/ssh_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ def _walk_directory(self, files, work_path, file_list, directory_list):
rel_file_list, work_path, file_list, directory_list
)
else:
raise RuntimeError(f"cannot find upload file {work_path} {jj}")
raise FileNotFoundError(f"cannot find upload file {work_path} {jj}")

def upload(
self,
Expand Down
4 changes: 2 additions & 2 deletions tests/test_local_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def test_upload_non_exist(self):

self.local_context.bind_submission(submission)

with self.assertRaises(RuntimeError):
with self.assertRaises(FileNotFoundError):
self.local_context.upload(submission)

def test_upload(self):
Expand Down Expand Up @@ -236,7 +236,7 @@ def test_download_check_exists(self):
submission_hash="0_md/",
)
self.local_context.bind_submission(submission)
with self.assertRaises(RuntimeError):
with self.assertRaises(FileNotFoundError):
self.local_context.download(submission, check_exists=False)

def test_download_mark_failure_tag(self):
Expand Down

0 comments on commit 3052136

Please sign in to comment.