From 1876dd154640b86088450ee5581420ffbbdfe8ee Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: Aug 22 2018 13:03:21 +0000 Subject: raise error for non-existing task in list_task_output Added strict option Fixes: https://pagure.io/koji/issue/1048 --- diff --git a/cli/koji_cli/commands.py b/cli/koji_cli/commands.py index 7341490..47f3e7a 100644 --- a/cli/koji_cli/commands.py +++ b/cli/koji_cli/commands.py @@ -6734,6 +6734,8 @@ def anon_handle_download_task(options, session, args): # get downloadable tasks base_task = session.getTaskInfo(base_task_id) + if not base_task: + parser.error(_("Task doesn't exist")) check_downloadable = lambda task: task["method"] == "buildArch" downloadable_tasks = [] diff --git a/hub/kojihub.py b/hub/kojihub.py index 2364d0a..24afa18 100644 --- a/hub/kojihub.py +++ b/hub/kojihub.py @@ -4454,7 +4454,7 @@ def get_archive_file(archive_id, filename, strict=False): return None -def list_task_output(taskID, stat=False, all_volumes=False): +def list_task_output(taskID, stat=False, all_volumes=False, strict=False): """List the files generated by the task with the given ID. This will usually include one or more RPMs, and one or more log files. If the task did not generate any files, or the output directory @@ -4482,7 +4482,17 @@ def list_task_output(taskID, stat=False, all_volumes=False): } } } + + If strict is set, function will raise a GenericError if task doesn't + exist. Allows user to distinguish between empty output and non-existent task. """ + if strict: + # raise error if task doesn't exist + try: + Task(taskID).getInfo(strict=True) + except: + raise koji.GenericError("Task doesn't exist") + if stat or all_volumes: result = {} else: