Skip to content

Commit

Permalink
Use sub-exception to allow catching just rclone errors (#26)
Browse files Browse the repository at this point in the history
* Use sub-exception to allow catching just rclone errors

* Fix init args of RcloneException

---------

Co-authored-by: Johannes Gundlach <[email protected]>
  • Loading branch information
kunaltyagi and Johannes11833 authored Nov 12, 2023
1 parent 20a6f88 commit 38caac7
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions rclone_python/rclone.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,13 @@ def version(
return yours, latest, beta


class RcloneException(ChildProcessError):
def __init__(self, description, error_msg):
self.description = description
self.error_msg = error_msg
super().__init__(f"{description}. Error message: \n{error_msg}")


@__check_installed
def _rclone_transfer_operation(
in_path: str,
Expand Down Expand Up @@ -606,7 +613,7 @@ def _rclone_transfer_operation(
logging.info("Cloud upload completed.")
else:
_, err = process.communicate()
raise Exception(
f"Copy/Move operation from {in_path} to {out_path}"
f' failed with error message:\n{err.decode("utf-8")}'
raise RcloneException(
description=f"{command_descr} from {in_path} to {out_path} failed",
error_msg=err.decode("utf-8"),
)

0 comments on commit 38caac7

Please sign in to comment.