Skip to content

Commit

Permalink
Move exception print statement earlier to avoid confusing log message…
Browse files Browse the repository at this point in the history
…s. Check for directories before trying to delete them.
  • Loading branch information
adammcdonagh authored Oct 19, 2024
1 parent 8060683 commit a51ffd8
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/opentaskpy/taskhandlers/transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ def return_result(
Returns:
bool: The result of the task run.
"""
# Log the exception
if exception:
self.logger.exception(exception)

# Delete the remote connection objects
if self.source_remote_handler:
self.logger.info("Closing source connection")
Expand All @@ -125,9 +129,6 @@ def return_result(
)

# Call super to do the rest
# Log the exception
if exception:
self.logger.exception(exception)
return super().return_result(status, message, exception) # type: ignore[no-any-return]

def _get_default_class(self, protocol_name: str) -> type:
Expand Down Expand Up @@ -639,7 +640,8 @@ def run(self, kill_event: threading.Event | None = None) -> bool: # noqa: C901
and self.local_staging_dir != self.source_file_spec["directory"]
):
self.logger.debug("Removing local staging directory")
shutil.rmtree(self.local_staging_dir)
if path.exists(self.local_staging_dir):
shutil.rmtree(self.local_staging_dir)
else:
self.logger.info("Performing filewatch only")

Expand Down Expand Up @@ -769,7 +771,8 @@ def encrypt_files(
encrypted_files[output_filename] = files[file]

# Remove the temporary gnupg keychain files under f"{tmpdir}/.gnupg"
shutil.rmtree(f"{tmpdir}/.gnupg")
if path.exists(f"{tmpdir}/.gnupg"):
shutil.rmtree(f"{tmpdir}/.gnupg")

return encrypted_files

Expand Down Expand Up @@ -830,7 +833,8 @@ def decrypt_files(self, files: dict, private_key: str) -> dict:
self.logger.error(f"GPG STDERR: {decryption_data.stderr}")

# Remove the temporary gnupg keychain files under f"{tmpdir}/.gnupg"
shutil.rmtree(f"{tmpdir}/.gnupg")
if path.exists(f"{tmpdir}/.gnupg"):
shutil.rmtree(f"{tmpdir}/.gnupg")

raise exceptions.DecryptionError(
f"Error decrypting file {file}: {decryption_data.status}"
Expand All @@ -839,7 +843,9 @@ def decrypt_files(self, files: dict, private_key: str) -> dict:
decrypted_files[output_filename] = files[file]

# Remove the temporary gnupg keychain files under f"{tmpdir}/.gnupg"
shutil.rmtree(f"{tmpdir}/.gnupg")
# Check if the directory exists first
if path.exists(f"{tmpdir}/.gnupg"):
shutil.rmtree(f"{tmpdir}/.gnupg")

self.logger.debug(f"Returning decrypted files: {decrypted_files}")

Expand Down

0 comments on commit a51ffd8

Please sign in to comment.