From 4918e05229e7a26a7ce0d1dd062061b075ae5e41 Mon Sep 17 00:00:00 2001 From: Donny Peeters Date: Tue, 9 May 2023 10:31:33 +0200 Subject: [PATCH 1/2] Better raw output to download in Rocky from Bytes on crashes --- boefjes/boefjes/job_handler.py | 5 +++-- boefjes/tests/test_tasks.py | 20 ++++++++++---------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/boefjes/boefjes/job_handler.py b/boefjes/boefjes/job_handler.py index 00d1cfcfcb9..a6b1c2bbdb3 100644 --- a/boefjes/boefjes/job_handler.py +++ b/boefjes/boefjes/job_handler.py @@ -1,4 +1,5 @@ import logging +import traceback from datetime import datetime, timedelta, timezone from enum import Enum from typing import Any, Dict, List, Set @@ -136,9 +137,9 @@ def handle(self, boefje_meta: BoefjeMeta) -> None: try: boefje_results = self.job_runner.run(boefje_meta, environment) - except Exception as e: + except Exception: logger.exception("Error running boefje %s[%s]", boefje_meta.boefje.id, boefje_meta.id) - boefje_results = [({"error/boefje"}, str(e))] + boefje_results = [({"error/boefje"}, traceback.format_exc())] raise finally: diff --git a/boefjes/tests/test_tasks.py b/boefjes/tests/test_tasks.py index 79d98c623b3..692b2a6239c 100644 --- a/boefjes/tests/test_tasks.py +++ b/boefjes/tests/test_tasks.py @@ -121,16 +121,16 @@ def test_handle_boefje_with_exception(self, mock_find_ooi_in_past, mock_bytes_ap BoefjeHandler(LocalBoefjeJobRunner(local_repository), local_repository).handle(meta) mock_bytes_api_client.save_boefje_meta.assert_called_once_with(meta) - mock_bytes_api_client.save_raw.assert_called_once_with( - "some-random-job-id", - "Boefje failed", - { - "error/boefje", - "dummy_boefje_runtime_exception", - "boefje/dummy_boefje_runtime_exception", - f"boefje/dummy_boefje_runtime_exception-{meta.parameterized_arguments_hash}", - }, - ) + mock_bytes_api_client.save_raw.assert_called_once() + assert mock_bytes_api_client.save_raw.call_args[0][0] == "some-random-job-id" + assert "Traceback (most recent call last)" in mock_bytes_api_client.save_raw.call_args[0][1] + assert "JobRuntimeError: Boefje failed" in mock_bytes_api_client.save_raw.call_args[0][1] + assert mock_bytes_api_client.save_raw.call_args[0][2] == { + "error/boefje", + "dummy_boefje_runtime_exception", + "boefje/dummy_boefje_runtime_exception", + f"boefje/dummy_boefje_runtime_exception-{meta.parameterized_arguments_hash}", + } def test_exception_raised_unsupported_return_type_normalizer(self): meta = NormalizerMeta.parse_raw(get_dummy_data("dns-normalize.json")) From 9341c8137d771ad2c0a4cb176cd270c8f9192239 Mon Sep 17 00:00:00 2001 From: Donny Peeters Date: Tue, 9 May 2023 12:17:49 +0200 Subject: [PATCH 2/2] Extract call arguments variable in test --- boefjes/tests/test_tasks.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/boefjes/tests/test_tasks.py b/boefjes/tests/test_tasks.py index 692b2a6239c..6c892051779 100644 --- a/boefjes/tests/test_tasks.py +++ b/boefjes/tests/test_tasks.py @@ -122,10 +122,12 @@ def test_handle_boefje_with_exception(self, mock_find_ooi_in_past, mock_bytes_ap mock_bytes_api_client.save_boefje_meta.assert_called_once_with(meta) mock_bytes_api_client.save_raw.assert_called_once() - assert mock_bytes_api_client.save_raw.call_args[0][0] == "some-random-job-id" - assert "Traceback (most recent call last)" in mock_bytes_api_client.save_raw.call_args[0][1] - assert "JobRuntimeError: Boefje failed" in mock_bytes_api_client.save_raw.call_args[0][1] - assert mock_bytes_api_client.save_raw.call_args[0][2] == { + raw_call_args = mock_bytes_api_client.save_raw.call_args + + assert raw_call_args[0][0] == "some-random-job-id" + assert "Traceback (most recent call last)" in raw_call_args[0][1] + assert "JobRuntimeError: Boefje failed" in raw_call_args[0][1] + assert raw_call_args[0][2] == { "error/boefje", "dummy_boefje_runtime_exception", "boefje/dummy_boefje_runtime_exception",