From e16dfc94bc40e3c678cfb7041031a4bb7a873a51 Mon Sep 17 00:00:00 2001 From: Dominik Rumian Date: Mar 31 2022 23:40:29 +0000 Subject: Better exit code for connection error When there is a connection failure while running _watch_build_tasks method then exit code '2' is returned and apropriate error message is logged. Jira: RHELCMP-5143 Signed-off-by: Dominik Rumian --- diff --git a/pyrpkg/cli.py b/pyrpkg/cli.py index 6423664..0f95bdc 100644 --- a/pyrpkg/cli.py +++ b/pyrpkg/cli.py @@ -1887,17 +1887,21 @@ class cliClient(object): :param list task_ids: a list of task IDs to watch. """ - if self.args.nowait: + if hasattr(self.args, 'nowait') and self.args.nowait: return # Pass info off to our koji task watcher - if self.args.dry_run: + if hasattr(self.args, 'dry_run') and self.args.dry_run: self.log.info('DRY-RUN: Watch tasks: %s', task_ids) else: - return koji_cli.lib.watch_tasks( - self.cmd.kojisession, - task_ids, - ki_handler=utils.make_koji_watch_tasks_handler(self.cmd.build_client) - ) + try: + return koji_cli.lib.watch_tasks( + self.cmd.kojisession, + task_ids, + ki_handler=utils.make_koji_watch_tasks_handler(self.cmd.build_client) + ) + except requests.exceptions.ConnectionError as e: + self.log.error('Could not finish the \'watch task\'. Reason: %s', e) + sys.exit(2) def extract_greenwave_url(self): greenwave_url = None