Skip to content

Commit

Permalink
Merge pull request #98 from CybercentreCanada/update/bug-fixes
Browse files Browse the repository at this point in the history
Skip image upload if error, and re-submit if no machines that match tag
  • Loading branch information
cccs-kevin authored Sep 12, 2022
2 parents 5495eef + 22b7fd4 commit e36667d
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions cape/cape_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -700,16 +700,24 @@ 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"]:
for error_dict in error.values():
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:
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e36667d

Please sign in to comment.