aboutsummaryrefslogtreecommitdiff
path: root/src/wikiget/wikiget.py
diff options
context:
space:
mode:
authorCody Logan <cody@lokken.dev>2023-10-17 14:00:14 -0700
committerCody Logan <cody@lokken.dev>2023-10-17 14:00:14 -0700
commit06335ba0176cabd84f5b548995f465ac1c09bc8e (patch)
tree1425c62c7371dd1c629a89b3c7a397e8e875268a /src/wikiget/wikiget.py
parent45a550899e0adf6958764d8a5133da4e21aa7fea (diff)
downloadwikiget-06335ba0176cabd84f5b548995f465ac1c09bc8e.tar.gz
wikiget-06335ba0176cabd84f5b548995f465ac1c09bc8e.zip
Clean up exception handling and error messages
Diffstat (limited to 'src/wikiget/wikiget.py')
-rw-r--r--src/wikiget/wikiget.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/wikiget/wikiget.py b/src/wikiget/wikiget.py
index 68e0233..4446f96 100644
--- a/src/wikiget/wikiget.py
+++ b/src/wikiget/wikiget.py
@@ -20,6 +20,9 @@ import logging
import sys
from concurrent.futures import ThreadPoolExecutor
+from mwclient import APIError, InvalidResponse, LoginError
+from requests import ConnectionError, HTTPError
+
import wikiget
from wikiget.dl import download, prep_download
from wikiget.exceptions import ParseError
@@ -178,6 +181,10 @@ def batch_download(args):
file = prep_download(line, args)
except ParseError as e:
logging.warning(f"{e} (line {line_num})")
+ except (ConnectionError, HTTPError, InvalidResponse, LoginError, APIError):
+ logging.error(
+ f"Unable to download '{line}' (line {line_num}) due to an error"
+ )
future = executor.submit(download, file, args)
futures.append(future)
# wait for downloads to finish
@@ -198,6 +205,8 @@ def main():
if args.batch:
# batch download mode
+ # TODO: return non-zero exit code if any errors were encountered, even if some
+ # downloads completed successfully
batch_download(args)
else:
# single download mode
@@ -206,4 +215,6 @@ def main():
except ParseError as e:
logging.error(e)
sys.exit(1)
+ except (ConnectionError, HTTPError, InvalidResponse, LoginError, APIError):
+ sys.exit(1)
download(file, args)