From 14f47f83b29eab547b64010de1e14366e13b2072 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Sun, 23 Dec 2018 15:50:43 +0100 Subject: [PATCH] Handle return code and exceptions better --- src/aria2p/__main__.py | 2 +- src/aria2p/cli.py | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/aria2p/__main__.py b/src/aria2p/__main__.py index 481fe20..93aac9d 100644 --- a/src/aria2p/__main__.py +++ b/src/aria2p/__main__.py @@ -13,4 +13,4 @@ from aria2p.cli import main if __name__ == "__main__": - main(sys.argv[1:]) + sys.exit(main(sys.argv[1:])) diff --git a/src/aria2p/cli.py b/src/aria2p/cli.py index 7c291c4..9f5a96a 100644 --- a/src/aria2p/cli.py +++ b/src/aria2p/cli.py @@ -69,18 +69,23 @@ def main(args=None): params = json.loads(args.json_params) if method is None: print(f"Unknown method {args.method}. Run '{sys.argv[0]} -m listmethods' to list the available methods.") - sys.exit(1) + return 1 try: response = client.call(method, params) except JSONRPCError as e: print(e.message) - sys.exit(e.code) + return e.code else: print(json.dumps(response)) return 0 api = API(client) - downloads = api.get_downloads() + + try: + downloads = api.get_downloads() + except Exception as e: + print(e) + return 1 print(f"{'GID':<17} {'STATUS':<9} {'PROGRESS':<8} {'DOWN_SPEED':<12} {'ETA':<8} NAME") for download in downloads: