upload: Raise exceptions instead of just returning None when errors occurs - transferwee - Download/upload file via wetransfer.com
(HTM) git clone https://github.com/iamleot/transferwee
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
---
(DIR) commit 5d921f6b936a0ce688ee9301c0a567fbea8bc7c8
(DIR) parent 234eec526ff552e0a7365b5c4330fee00d01846a
(HTM) Author: Leonardo Taccari <iamleot@gmail.com>
Date: Sun, 2 Jun 2019 15:03:10 +0200
upload: Raise exceptions instead of just returning None when errors occurs
Previously when trying to upload non-existing filenames or duplicate
filenames None was returned and printed and transferwee exited with
status 0 without providing useful information. Respectively raise
FileNotFoundError() and FileExistsError() exceptions when that happens.
Should fix issue #5.
Diffstat:
M transferwee.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
---
(DIR) diff --git a/transferwee.py b/transferwee.py
@@ -260,13 +260,13 @@ def upload(files: List[str], message: str = '', sender: str = None,
# Check that all files exists
for f in files:
if not os.path.exists(f):
- return None
+ raise FileNotFoundError(f)
# Check that there are no duplicates filenames
# (despite possible different dirname())
filenames = [os.path.basename(f) for f in files]
if len(files) != len(set(filenames)):
- return None
+ raise FileExistsError('Duplicate filenames')
transfer_id = None
if sender and recipients: