From 4fb1ad7ef329f68d2fd5c321d22c99fc77e13b9b Mon Sep 17 00:00:00 2001 From: "Chris (ChrisJr404)" <11917633+ChrisJr404@users.noreply.github.com> Date: Sun, 3 May 2026 11:35:54 -0400 Subject: [PATCH] fix(worker): surface the underlying exception when a work item fails (#2227) The async worker that drains the engine queue catches `Exception` with no `as` binding and prints the bare line "A error occurred while processing a 'work item'." That message both swallows the actual error class+text (so users report bugs like #2227 with no actionable detail and the maintainer has to ask them to repro under more verbosity) and reads "A error" instead of the grammatical "An error". Bind the exception, print its type and message, and fix the article. The shodan integration test (`tests/discovery/test_shodan_engine.py`) already asserts the message is not in output on the happy path; the assertion is updated to match the new string. Closes #2227. --- tests/discovery/test_shodan_engine.py | 2 +- theHarvester/__main__.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/discovery/test_shodan_engine.py b/tests/discovery/test_shodan_engine.py index 5c08206d..1b0f0c3d 100644 --- a/tests/discovery/test_shodan_engine.py +++ b/tests/discovery/test_shodan_engine.py @@ -39,6 +39,6 @@ class TestShodanEngine: assert excinfo.value.code == 0 out = capsys.readouterr().out - assert 'A error occurred while processing a "work item"' not in out + assert 'An error occurred while processing a "work item"' not in out assert "a.example.com" in out assert "b.example.com" in out diff --git a/theHarvester/__main__.py b/theHarvester/__main__.py index cd0d7e5b..680135ff 100644 --- a/theHarvester/__main__.py +++ b/theHarvester/__main__.py @@ -1301,8 +1301,8 @@ async def start(rest_args: argparse.Namespace | None = None): await stor queue.task_done() # Notify the queue that the "work item" has been processed. - except Exception: - print('\n A error occurred while processing a "work item".\n') + except Exception as work_item_error: + print(f'\n An error occurred while processing a "work item": {type(work_item_error).__name__}: {work_item_error}\n') queue.task_done() async def handler(lst):