From 22b7fd4a1703687e46c995fbc33fe959d076d300 Mon Sep 17 00:00:00 2001 From: cccs-kevin Date: Mon, 12 Sep 2022 12:06:01 +0000 Subject: [PATCH] Skip image upload if error, and re-submit if no machines that match tag --- cape/cape_main.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/cape/cape_main.py b/cape/cape_main.py index d879c7a..142e824 100644 --- a/cape/cape_main.py +++ b/cape/cape_main.py @@ -700,6 +700,7 @@ def submit_file(self, file_content: bytes, cape_task: CapeTask) -> int: resp_json = resp.json() if "error" in resp_json and resp_json['error']: self.log.error(f"Failed to submit the file with {cape_task.submit_url} due to '{resp_json['error_value']}'.") + incorrect_tag = False if "errors" in resp_json and resp_json["errors"]: try: for error in resp_json["errors"]: @@ -707,9 +708,16 @@ def submit_file(self, file_content: bytes, cape_task: CapeTask) -> int: for k, v in error_dict.items(): if k == "error": self.log.error(f'Further details about the error are: {v}') + incorrect_tag = "Check Tags help, you have introduced incorrect tag(s)." in v except Exception: pass - raise InvalidCapeRequest("There is most likely an issue with how the service is configured to interact with CAPE's REST API. Check the service logs for more details.") + + if self.retry_on_no_machine and incorrect_tag: + # No need to log here because the log.error above containing further details about the error has happened + sleep(self.timeout) + raise RecoverableError("Retrying since the specific image was missing...") + else: + raise InvalidCapeRequest("There is most likely an issue with how the service is configured to interact with CAPE's REST API. Check the service logs for more details.") elif "data" in resp_json and resp_json["data"]: task_ids = resp_json["data"].get("task_ids", []) if isinstance(task_ids, list) and len(task_ids) > 0: @@ -1626,7 +1634,10 @@ def _extract_artifacts(self, zip_obj: ZipFile, task_id: int, cape_artifact_pids: to_be_extracted = False # AL generates thumbnails already if "_small" not in f: - image_section.add_image(destination_file_path, file_name, value) + try: + image_section.add_image(destination_file_path, file_name, value) + except OSError as e: + self.log.debug(f"Unable to add image due to {e}") continue else: to_be_extracted = True